change name mtx_msg for m_print, malloc mutex instead of equal NULL, malloc id with pthread_t instead of int, and change name some functions
This commit is contained in:
12
srcs/init.c
12
srcs/init.c
@@ -1,6 +1,6 @@
|
||||
#include "philo.h"
|
||||
|
||||
t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i)
|
||||
t_philo *lst_add_philo(t_philo *philo, t_params *params, t_mtx *m_print, int i)
|
||||
{
|
||||
t_philo *new;
|
||||
|
||||
@@ -10,7 +10,7 @@ t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i)
|
||||
new->params = params;
|
||||
new->philo_nbr = i + 1;
|
||||
new->fork = 1;
|
||||
new->msg_mtx = mtx;
|
||||
new->m_print = m_print;
|
||||
if (philo)
|
||||
philo->next = new;
|
||||
new->prev = philo;
|
||||
@@ -18,7 +18,7 @@ t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i)
|
||||
}
|
||||
|
||||
// looping chained list
|
||||
t_philo *init_chain_philo(t_params *params, t_mtx *mutex)
|
||||
t_philo *init_chain_philo(t_params *params, t_mtx *m_print)
|
||||
{
|
||||
t_philo *end;
|
||||
t_philo *philo;
|
||||
@@ -28,7 +28,7 @@ t_philo *init_chain_philo(t_params *params, t_mtx *mutex)
|
||||
philo = NULL;
|
||||
while (i < params->n_phi)
|
||||
{
|
||||
philo = create_each_philo(philo, params, mutex, i);
|
||||
philo = lst_add_philo(philo, params, m_print, i);
|
||||
i++;
|
||||
}
|
||||
end = philo;
|
||||
@@ -67,10 +67,10 @@ t_philo *init(int ac, char **av, pthread_t **id)
|
||||
params = init_params(ac, av);
|
||||
if (params == NULL)
|
||||
return (NULL);
|
||||
*id = malloc(sizeof(int) * params->n_phi);
|
||||
*id = malloc(sizeof(pthread_t) * params->n_phi);
|
||||
if (*id == NULL)
|
||||
return (NULL);
|
||||
m_print = NULL;
|
||||
m_print = malloc(sizeof(t_mtx));
|
||||
if (pthread_mutex_init(m_print, NULL) != 0)
|
||||
return (NULL);
|
||||
philo = init_chain_philo(params, m_print);
|
||||
|
||||
Reference in New Issue
Block a user