/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* philo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet #include #include #include #include #include "./print.h" #include "philo.h" #include "time.h" #include "data.h" void philo_destroyer(t_philo *philo) { pthread_mutex_destroy(&philo->nb_meal_mutex); pthread_mutex_destroy(&philo->last_eat_mutex); free(philo); } t_philo *philo_init(t_data *data) { t_philo *philo; static size_t id = 0; philo = malloc(sizeof(t_philo)); if (philo == NULL) return (NULL); philo->id = id++; philo->data = data; philo->nb_meal = 0; philo->stop = 0; philo->last_eat = get_time(); pthread_mutex_init(&philo->nb_meal_mutex, NULL); pthread_mutex_init(&philo->last_eat_mutex, NULL); pthread_mutex_init(&philo->stop_mutex, NULL); return (philo); }