diff --git a/philo/init_fork.c b/philo/init_fork.c deleted file mode 100644 index c69bf17..0000000 --- a/philo/init_fork.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* init_fork.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/07/16 19:53:01 by adjoly #+# #+# */ -/* Updated: 2024/07/18 21:03:00 by adjoly ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void init_fork(t_philo *philo, t_pdata data) -{ - int i; - - i = 0; - while (philo[i] && i <= data.philo_nbr) - { - pthread_mutex_init(philo[i].fork.left); - if (i == data.philo_nbr) - philo[i].fork.right = &philo[0].fork.left; - else - philo[i].fork.right = &philo[i + 1].fork.left; - i++; - } -} diff --git a/philo/init_philo.c b/philo/init_philo.c index 35be015..1e4b19a 100644 --- a/philo/init_philo.c +++ b/philo/init_philo.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 14:36:59 by adjoly #+# #+# */ -/* Updated: 2024/07/17 22:53:48 by adjoly ### ########.fr */ +/* Updated: 2024/07/22 14:05:52 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,21 +14,22 @@ void init_philo(t_pdata data) { - t_philo philo[PHILO_MAX]; - t_philo *tmp; + t_init init[PHILO_MAX]; pthread_mutex_t *print; int ret; - tmp = philo; i = 0; init_fork(philo, data); - while (tmp && i < data->philo_nbr) + while (i < data->philo_nbr) { - ret = pthread_create(&(tmp->thread), NULL, philo_routine, tmp); + ret = pthread_create(&(init[i]->thread), NULL, philo_routine, tmp); if (ret != 0) return ; - tmp->data = data; - tmp->state = EAT; - tmp++; + init[i]->philo->nbr = i; + gettimeofday(&(init[i]->philo->t0), NULL) + init[i]->philo->data = data; + init[i]->philo->state = EAT; + init[i]->philo->fork = init_fork(init, i, data->philo_nbr); + i++; } } diff --git a/philo/philo.h b/philo/philo.h index 6092cf5..682fa8d 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/07/21 21:55:26 by adjoly ### ########.fr */ +/* Updated: 2024/07/22 14:01:27 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,14 +69,11 @@ t_pdata philo_parse(char **argv, int ac); long long ft_atoll(const char *nptr); uint16_t get_time_in_ms(struct timeval t0, struct timeval t1); -void *philo_routine(void *param); /** * Main path * by order of call */ t_philo *init_philo(t_pdata data, uint16_t philo_nbr); -void init_fork(t_philo *philo, t_pdata data); -void start_philo(t_philo *philo, t_pdata data); /** * For debug purpose to be REMOVED diff --git a/philo/philo_routine.c b/philo/philo_routine.c deleted file mode 100644 index 149b197..0000000 --- a/philo/philo_routine.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* philo_routine.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/07/16 19:54:02 by adjoly #+# #+# */ -/* Updated: 2024/07/16 20:57:54 by adjoly ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void *philo_routine(void *param) -{ - t_philo philo; - - philo = (t_philo)param; - log -} diff --git a/philo/start_philo.c b/philo/start_philo.c deleted file mode 100644 index fdb2355..0000000 --- a/philo/start_philo.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* start_philo.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/07/18 18:31:21 by adjoly #+# #+# */ -/* Updated: 2024/07/18 19:08:43 by adjoly ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void start_philo(t_philo *philo, t_pdata data) -{ - int i; - int ret; - - i = 0; - while (philo[i] && i < data.philo_nbr) - { - ret = pthread_join(&(philo->thread), NULL); - if (ret != 0) - return ; - i++; - } -}