From 56afbb3011c346dfc0d9e6d92e76cb13fdb272c8 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sat, 18 Jan 2025 12:50:55 +0100 Subject: [PATCH] Add ft_log func --- philo/include/ft_utils.h | 4 +++- philo/include/philo.h | 3 +-- philo/src/ft_utils.c | 12 +++++++++++- philo/src/simulation.c | 10 ++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/philo/include/ft_utils.h b/philo/include/ft_utils.h index 3c9bd69..4000815 100644 --- a/philo/include/ft_utils.h +++ b/philo/include/ft_utils.h @@ -6,7 +6,7 @@ /* By: dkaiser # include +# include /* ** Prints error message and returns EXIT_FAILURE @@ -26,4 +27,5 @@ int ft_err(const char *str); */ int ft_atoi(const char *str); +void ft_log(int id, const char *str); #endif diff --git a/philo/include/philo.h b/philo/include/philo.h index 9566136..308857b 100644 --- a/philo/include/philo.h +++ b/philo/include/philo.h @@ -6,7 +6,7 @@ /* By: dkaiser # include # include -# include # include "ft_utils.h" # define ERR_USAGE "Usage: [times_must_eat]" diff --git a/philo/src/ft_utils.c b/philo/src/ft_utils.c index 9eb660a..7570b1d 100644 --- a/philo/src/ft_utils.c +++ b/philo/src/ft_utils.c @@ -6,7 +6,7 @@ /* By: dkaiser mutex); pthread_mutex_lock(&right_fork->mutex); left_fork->available = 0; + ft_log(philo->id, "has taken a fork"); right_fork->available = 0; - printf("Philo %d is eating\n", philo->id); + ft_log(philo->id, "has taken a fork"); + ft_log(philo->id, "is eating"); usleep(1000000); left_fork->available = 1; right_fork->available = 1; @@ -37,13 +39,13 @@ void philo_eat(t_philo *philo) void philo_sleep(t_philo *philo) { - printf("Philo %d is sleeping\n", philo->id); + ft_log(philo->id, "is sleeping"); usleep(1000000); } void philo_think(t_philo *philo) { - printf("Philo %d is thinking\n", philo->id); + ft_log(philo->id, "is thinking"); } int *process_philo(void *arg) -- 2.47.2