From 280dace8bf97242151faf8297af31de67f77085c Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 2 Jan 2021 10:51:53 +0100 Subject: Norming philo_one --- philo_one/src/routine.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'philo_one/src/routine.c') 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } -- cgit