From: Dominik Kaiser Date: Sat, 18 Jan 2025 11:50:55 +0000 (+0100) Subject: Add ft_log func X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=56afbb3011c346dfc0d9e6d92e76cb13fdb272c8;p=42%2FPhilosophers.git Add ft_log func --- 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)