/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* philo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud@student.42nice.fr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/18 22:23:52 by narnaud@stude #+# #+# */ /* Updated: 2022/05/19 00:42:59 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PHILO_H # define PHILO_H # include # include # include # include # include # include enum e_params { PHILO_AMOUNT, DIE_TIME, EAT_DURATION, SLEEP_DURATION, MEALS_AMOUNT, }; typedef struct s_room { int param[5]; pthread_mutex_t *lock; pthread_mutex_t *forks; int running; } t_room; typedef struct s_philo { t_room *room; pthread_mutex_t *fork; pthread_mutex_t *fork_r; pthread_mutex_t *next; pthread_mutex_t *lock; pthread_t *thd; int eat_time; int eat_amount; int id; } t_philo; // ---------------------------------- philo_init t_room *create_room(char **argv); t_philo *create_philos(t_room *room); void invit_philos(t_philo *philos); // ---------------------------------- philo_life void *philos_life(void *r); // ---------------------------------- philo_utils int safe_print(t_philo *philo, char *str); int safe_wait(t_room *room, int start, int duration); int room_clock(); int mini_atoi(char *nbr); #endif