diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-02 12:08:59 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-02 12:08:59 +0100 |
| commit | 7aab8f34e8a238ce0688bf9f7e7f0b731902580f (patch) | |
| tree | 6ab0541168d07c2755c51d9ef6875012105816e8 /philo_two/src/event.c | |
| parent | 280dace8bf97242151faf8297af31de67f77085c (diff) | |
| download | philosophers-7aab8f34e8a238ce0688bf9f7e7f0b731902580f.tar.gz philosophers-7aab8f34e8a238ce0688bf9f7e7f0b731902580f.tar.bz2 philosophers-7aab8f34e8a238ce0688bf9f7e7f0b731902580f.zip | |
Updated philo_two with philo_three logic, Norming philo_two and philo_three
Diffstat (limited to 'philo_two/src/event.c')
| -rw-r--r-- | philo_two/src/event.c | 52 |
1 files changed, 11 insertions, 41 deletions
diff --git a/philo_two/src/event.c b/philo_two/src/event.c index 0eaad11..0544042 100644 --- a/philo_two/src/event.c +++ b/philo_two/src/event.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2021/01/01 15:57:43 by charles ### ########.fr */ +/* Updated: 2021/01/02 11:25:08 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,79 +14,49 @@ void event_take_fork(t_philo *arg) { - if (philo_finished(arg->conf)) - return ; sem_wait(arg->forks); - if (philo_finished(arg->conf)) - return ; sem_wait(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; philo_put(arg->id, EVENT_FORK); - if (philo_finished(arg->conf)) - return ; sem_post(arg->conf->sem_stdout); } void event_eat(t_philo *arg) { - if (philo_finished(arg->conf)) - return ; sem_wait(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; philo_put(arg->id, EVENT_EAT); - if (philo_finished(arg->conf)) - return ; sem_post(arg->conf->sem_stdout); usleep(arg->conf->timeout_eat * 1000); } void event_think(t_philo *arg) { - if (philo_finished(arg->conf)) - return ; sem_wait(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; philo_put(arg->id, EVENT_THINK); - if (philo_finished(arg->conf)) - return ; sem_post(arg->conf->sem_stdout); } void event_sleep(t_philo *arg) { - if (philo_finished(arg->conf)) - return ; sem_wait(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; philo_put(arg->id, EVENT_SLEEP); - if (philo_finished(arg->conf)) - return ; sem_post(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; sem_post(arg->forks); - if (philo_finished(arg->conf)) - return ; sem_post(arg->forks); - if (philo_finished(arg->conf)) - return ; usleep(arg->conf->timeout_sleep * 1000); } void event_die(t_philo *arg) { - if (philo_finished(arg->conf)) - return ; + long int i; + sem_wait(arg->conf->sem_stdout); - if (philo_finished(arg->conf)) - return ; philo_put(arg->id, EVENT_DIE); - arg->conf->all_alive = false; - if (philo_finished(arg->conf)) - return ; - sem_post(arg->conf->sem_stdout); + if (arg->conf->meal_num == -1) + sem_post(arg->conf->sem_finish); + else + { + i = -1; + while (++i < arg->conf->philo_num) + sem_post(arg->conf->sem_finish); + } } |
