diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-30 09:52:21 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-30 09:52:21 +0200 |
| commit | 94d33564ee659d2fd0b084a4b4046e7b69ee0d9b (patch) | |
| tree | 26557e562ef0629f9023c467be04fcecf3ddb6f4 /philo_one/src/routine.c | |
| parent | 608ae732eccfe50f2727823f9aebe1f32681edfb (diff) | |
| download | philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.tar.gz philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.tar.bz2 philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.zip | |
Refactoring philo_one, removing mutex_all_alive and t_routine_args bloat
Diffstat (limited to 'philo_one/src/routine.c')
| -rw-r--r-- | philo_one/src/routine.c | 15 |
1 files changed, 6 insertions, 9 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } |
