reorganisation structs et timestamp global

This commit is contained in:
Hugo LAMY
2022-01-22 12:41:30 +01:00
parent 6a4aad9503
commit 3ba76ccc4e
5 changed files with 34 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
#include "philo.h"
t_philo *lst_add_philo(t_params *params, t_mtx *m_print, int *death, int i)
t_philo *lst_add_philo(t_params *params, t_mtx *m_print, int i)
{
t_philo *new;
@@ -12,13 +12,12 @@ t_philo *lst_add_philo(t_params *params, t_mtx *m_print, int *death, int i)
if (pthread_mutex_init(&(new->m_fork), NULL) != 0)
return (NULL);
new->m_print = m_print;
new->death = death;
new->next = NULL;
return (new);
}
// looping chained list
t_philo *init_chain_philo(t_params *params, t_mtx *m_print, int *death)
t_philo *init_chain_philo(t_params *params, t_mtx *m_print)
{
t_philo *philo;
t_philo *tmp;
@@ -29,7 +28,7 @@ t_philo *init_chain_philo(t_params *params, t_mtx *m_print, int *death)
philo = NULL;
while (i < params->n_phi)
{
tmp = lst_add_philo(params, m_print, death, i);
tmp = lst_add_philo(params, m_print, i);
if (philo)
philo->next = tmp;
else
@@ -54,6 +53,9 @@ t_params *init_params(int ac, char **av)
params->t_slp = ft_atoi(av[4]);
if (ac == 6)
params->n_eat = ft_atoi(av[5]);
params->dead = 0;
params->t_start_s = 0;
params->t_start_u = 0;
}
else
return (NULL);
@@ -65,7 +67,6 @@ t_philo *init(int ac, char **av, pthread_t **id)
t_philo *philo;
t_params *params;
t_mtx *m_print;
int death;
params = init_params(ac, av);
if (params == NULL)
@@ -76,8 +77,7 @@ t_philo *init(int ac, char **av, pthread_t **id)
m_print = malloc(sizeof(t_mtx));
if (pthread_mutex_init(m_print, NULL) != 0)
return (NULL);
death = 0;
philo = init_chain_philo(params, m_print, &death);
philo = init_chain_philo(params, m_print);
if (philo == NULL)
return (NULL);
return (philo);