From ac500fcfc12f2229e4b76dccf13894693aefbd6d Mon Sep 17 00:00:00 2001 From: biralavor Date: Wed, 30 Oct 2024 16:42:02 -0300 Subject: [PATCH] building sleeping routine --- philo/headers/philo.h | 3 ++- philo/src/08.dinner_manager.c | 6 +++--- philo/src/12.dinner_routines.c | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/philo/headers/philo.h b/philo/headers/philo.h index 1e37aec..5a695ae 100644 --- a/philo/headers/philo.h +++ b/philo/headers/philo.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 16:04:11 by umeneses #+# #+# */ -/* Updated: 2024/10/30 16:40:10 by umeneses ### ########.fr */ +/* Updated: 2024/10/30 16:40:57 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -149,6 +149,7 @@ void printer_with_mutex_debug(t_philo_status status, t_philo *philo, bool debbug /* dinner routines functions */ void let_philo_eat_routine(t_philo *philo); void let_philo_think_routine(t_philo *philo); +void let_philo_sleep_routine(t_philo *philo); /* LIBFT utility functions */ int ft_strlen(const char *str); diff --git a/philo/src/08.dinner_manager.c b/philo/src/08.dinner_manager.c index a875833..a459596 100644 --- a/philo/src/08.dinner_manager.c +++ b/philo/src/08.dinner_manager.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 10:01:45 by umeneses #+# #+# */ -/* Updated: 2024/10/30 16:29:27 by umeneses ### ########.fr */ +/* Updated: 2024/10/30 16:39:45 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,7 @@ void dinner_startup_runner(t_table *table) if (table->philo->full) // TODO: thread safe break ; let_philo_eat_routine(table->philo); - let_think_routine(table->philo); - // let_sleep_routine(table->philo); // TODO + let_philo_think_routine(table->philo); + let_philo_sleep_routine(table->philo); } } diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index 8cb0141..e4d5ed0 100644 --- a/philo/src/12.dinner_routines.c +++ b/philo/src/12.dinner_routines.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:19:23 by umeneses #+# #+# */ -/* Updated: 2024/10/30 16:40:25 by umeneses ### ########.fr */ +/* Updated: 2024/10/30 16:41:36 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,3 +37,8 @@ void let_philo_think_routine(t_philo *philo) // safe_mutex_handler(philo->philo_mtx, UNLOCK); } +void let_philo_sleep_routine(t_philo *philo) +{ + printer_with_mutex(SLEEPING, philo, false); + precise_usleep(philo->table->set->time_to_sleep, philo->table); +}