diff --git a/philo/monitor.c b/philo/monitor.c index 0db9d58..e2b3fe0 100644 --- a/philo/monitor.c +++ b/philo/monitor.c @@ -6,12 +6,20 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/12 12:13:35 by adjoly #+# #+# */ -/* Updated: 2024/08/19 23:19:17 by adjoly ### ########.fr */ +/* Updated: 2024/08/20 15:43:56 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo.h" +bool unlock_death(t_philo *philo, uint8_t i) +{ + pthread_mutex_unlock(philo->check); + pthread_mutex_unlock(&philo[i].fork.left); + pthread_mutex_unlock(philo[i].fork.right); + return (print_death(&philo[i])); +} + bool philo_check(t_philo *philo, t_pdata data) { uint8_t i; @@ -22,19 +30,13 @@ bool philo_check(t_philo *philo, t_pdata data) eaten = 0; while (i < data.philo_nbr) { - gettimeofday(&t1, NULL); pthread_mutex_lock(philo->check); if (get_time_in_ms(philo[i].eat, t1) > data.die_time + 1) - { - pthread_mutex_unlock(philo->check); - pthread_mutex_unlock(&philo[i].fork.left); - pthread_mutex_unlock(philo[i].fork.right); - return (print_death(&philo[i])); - } - pthread_mutex_unlock(philo->check); + return (unlock_death(philo, i)); if (philo[i].meal_left == 0) eaten++; + pthread_mutex_unlock(philo->check); if (get_death(philo, RETURN)) return (true); i++; diff --git a/philo/parsing.c b/philo/parsing.c index 99355dc..a559576 100644 --- a/philo/parsing.c +++ b/philo/parsing.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/08 15:30:46 by adjoly #+# #+# */ -/* Updated: 2024/08/13 10:32:25 by adjoly ### ########.fr */ +/* Updated: 2024/08/20 15:44:22 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,6 @@ t_pdata meal_nb(char **av, t_pdata data) return (data); } - t_pdata fill_pdata(char **av) { t_pdata data; diff --git a/philo/philo.h b/philo/philo.h index b04e491..aef465e 100644 --- a/philo/philo.h +++ b/philo/philo.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/07 15:11:02 by adjoly #+# #+# */ -/* Updated: 2024/08/12 19:04:16 by adjoly ### ########.fr */ +/* Updated: 2024/08/20 15:44:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ typedef struct s_philo pthread_mutex_t *check; } t_philo; -typedef enum s_bool_death +typedef enum s_bool_death { RETURN = -1, FALSE,