diff options
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); + } } |
