diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-02 10:51:53 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-02 10:51:53 +0100 |
| commit | 280dace8bf97242151faf8297af31de67f77085c (patch) | |
| tree | 7fa68ce3deb4d9236d13de5c05201fcb491b6887 /philo_one/src/routine.c | |
| parent | a73b1e33ae3a4f55e3dd19defa1b853bc58f1eeb (diff) | |
| download | philosophers-280dace8bf97242151faf8297af31de67f77085c.tar.gz philosophers-280dace8bf97242151faf8297af31de67f77085c.tar.bz2 philosophers-280dace8bf97242151faf8297af31de67f77085c.zip | |
Norming philo_one
Diffstat (limited to 'philo_one/src/routine.c')
| -rw-r--r-- | philo_one/src/routine.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/philo_one/src/routine.c b/philo_one/src/routine.c index d8fa3a0..6ee37f1 100644 --- a/philo_one/src/routine.c +++ b/philo_one/src/routine.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 01:11:27 by cacharle #+# #+# */ -/* Updated: 2021/01/01 14:24:05 by charles ### ########.fr */ +/* Updated: 2021/01/02 10:51:36 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,17 @@ inline bool philo_finished(t_philo_conf *conf) conf->meal_num_finished_counter == conf->philo_num)); } +static void st_check_meal_num_finished(t_philo *arg, long int eat_counter) +{ + if (!philo_finished(arg->conf) && arg->conf->meal_num != -1 && + eat_counter == arg->conf->meal_num) + { + pthread_mutex_lock(&arg->conf->mutex_meal_num_finished_counter); + arg->conf->meal_num_finished_counter++; + pthread_mutex_unlock(&arg->conf->mutex_meal_num_finished_counter); + } +} + void *routine_philo(t_philo *arg) { pthread_t thread_death; @@ -38,13 +49,7 @@ void *routine_philo(t_philo *arg) event_eat(arg); arg->time_last_eat = h_time_now(); eat_counter++; - if (!philo_finished(arg->conf) && arg->conf->meal_num != -1 && - eat_counter == arg->conf->meal_num) - { - pthread_mutex_lock(&arg->conf->mutex_meal_num_finished_counter); - arg->conf->meal_num_finished_counter++; - pthread_mutex_unlock(&arg->conf->mutex_meal_num_finished_counter); - } + st_check_meal_num_finished(arg, eat_counter); event_sleep(arg, arg->fork_right, arg->fork_left); event_think(arg); } |
