From 6f7b3a44d2916aaa99bd89f4e3371f9567a962da Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 24 Jul 2024 12:33:15 +0200 Subject: [PATCH] Pushing from the laptop the sources --- philo/includes/philo.h | 8 ++++---- philo/sources/parsing_args.c | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/philo/includes/philo.h b/philo/includes/philo.h index 57e7eee..3429142 100644 --- a/philo/includes/philo.h +++ b/philo/includes/philo.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 11:34:04 by rparodi #+# #+# */ -/* Updated: 2024/07/18 21:17:07 by rparodi ### ########.fr */ +/* Updated: 2024/07/23 21:04:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,11 +42,11 @@ typedef struct s_philo t_usize t_eat; t_usize t_death; t_usize t_sleep; - t_i32 nb_eat; + t_usize nb_eat; pthread_t thread; t_i32 id; t_i32 eating; - t_i32 eating_count; + t_usize eating_count; t_usize t_last_eat; t_usize start_time; t_bool dead_check; @@ -87,7 +87,7 @@ t_error ft_ending_eating(t_philo *philo); void ft_putchar_fd(t_i32 fd, t_str str); void ft_logs(t_str msg, t_philo *philo); t_error ft_atou(const char *nptr, t_usize *value); -t_error ft_init_fork(t_philo *philo, t_mutex *fork); +t_error ft_init_fork(t_mutex *fork, t_usize nb_fork); void counting_launch(t_philo *philo, t_u8 *counter); t_error ft_init_thread(t_program *prog, t_mutex *forks); t_error ft_parsing_args(t_i32 argc, t_str *argv, t_philo *philo); diff --git a/philo/sources/parsing_args.c b/philo/sources/parsing_args.c index f5653cc..3495d51 100644 --- a/philo/sources/parsing_args.c +++ b/philo/sources/parsing_args.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 11:42:37 by rparodi #+# #+# */ -/* Updated: 2024/07/23 20:03:47 by rparodi ### ########.fr */ +/* Updated: 2024/07/23 21:07:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,14 +40,15 @@ t_error ft_parsing_args(t_i32 argc, t_str *argv, t_philo *philo) return (NO_ERROR); } -t_error ft_init_fork(t_philo *philo, t_mutex *fork) +t_error ft_init_fork(t_mutex *fork, t_usize nb_fork) { t_usize i; i = 0; - while (i < philo->nb_philo) + while (i < nb_fork) { - pthread_mutex_init(&fork[i], NULL); + printf("\tforks[%zu]\n", i + 1); + fork[i] = (t_mutex)PTHREAD_MUTEX_INITIALIZER; i++; } return (NO_ERROR); @@ -82,6 +83,7 @@ t_error ft_init_philo(t_i32 argc, t_str *argv, t_program *prog, t_mutex *forks) prog->philos[i].r_fork = &forks[prog->philos[i].nb_philo - 1]; else prog->philos[i].r_fork = &forks[i - 1]; + printf("\tphilo[%zu]\n", i + 1); i++; } if (ft_parsing_args(argc, argv, prog->philos)) @@ -97,9 +99,9 @@ t_error ft_init(t_i32 argc, t_str *argv, t_program *prog, t_philo *philo) prog->dead_lock = (t_mutex)PTHREAD_MUTEX_INITIALIZER; prog->meal_lock = (t_mutex)PTHREAD_MUTEX_INITIALIZER; prog->check_eating_count = (t_mutex)PTHREAD_MUTEX_INITIALIZER; - ft_init_fork(prog->philos, forks); prog->philos = philo; prog->dead_flag = false; + ft_init_fork(forks, ft_atou_return(argv[1])); if (ft_init_philo(argc, argv, prog, forks)) return (ERROR); if (philo->nb_philo != 0 && philo->nb_philo > MAXSUPPORT)