From 94d33564ee659d2fd0b084a4b4046e7b69ee0d9b Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Wed, 30 Sep 2020 09:52:21 +0200 Subject: Refactoring philo_one, removing mutex_all_alive and t_routine_args bloat --- philo_one/src/routine.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'philo_one/src/routine.c') diff --git a/philo_one/src/routine.c b/philo_one/src/routine.c index 4b829f0..5f76a26 100644 --- a/philo_one/src/routine.c +++ b/philo_one/src/routine.c @@ -6,19 +6,19 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 01:11:27 by cacharle #+# #+# */ -/* Updated: 2020/09/30 08:38:59 by cacharle ### ########.fr */ +/* Updated: 2020/09/30 09:43:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo_one.h" -void *routine_philo(t_routine_arg *arg) +void *routine_philo(t_philo *arg) { pthread_t thread_death; if (!arg->conf->all_alive) return (NULL); - arg->philo->time_last_eat = h_time_now(); + arg->time_last_eat = h_time_now(); if (pthread_create(&thread_death, NULL, (t_routine)routine_death, arg) != 0) return (NULL); io_think(arg); @@ -26,7 +26,7 @@ void *routine_philo(t_routine_arg *arg) { io_take_fork(arg, arg->fork_left); io_take_fork(arg, arg->fork_right); - arg->philo->time_last_eat = h_time_now(); + arg->time_last_eat = h_time_now(); io_eat(arg); io_sleep(arg, arg->fork_right, arg->fork_left); io_think(arg); @@ -35,19 +35,16 @@ void *routine_philo(t_routine_arg *arg) return (NULL); } -void *routine_death(t_routine_arg *arg) +void *routine_death(t_philo *arg) { t_time current; current = h_time_now(); while (arg->conf->all_alive && - current - arg->philo->time_last_eat < arg->conf->timeout_death) + current - arg->time_last_eat < arg->conf->timeout_death) current = h_time_now(); if (!arg->conf->all_alive) return (NULL); - pthread_mutex_lock(&arg->conf->mutex_all_alive); io_die(arg); - arg->conf->all_alive = false; - pthread_mutex_unlock(&arg->conf->mutex_all_alive); return (NULL); } -- cgit