/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* philo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 14:51:16 by erey-bet #+# #+# */ /* Updated: 2023/04/10 11:21:38 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PHILO_H # define PHILO_H # include "utils/utils.h" # include # include # include typedef struct s_config { int nbr_philo; long time_die; long time_eat; long time_sleep; long must_eat; } t_config; typedef struct s_same { t_config *config; int *forks; pthread_mutex_t *mutex; int all_eat; int death; long long time; } t_same; typedef struct s_only { int id; int next_id; long long last_eat_time; int eat; } t_only; typedef struct s_philo { t_same *same; t_only *only; } t_philo; /* PARSING */ int parsing(char *argv[], t_config *conf); /* MANAGE THREADS */ int manage_threads(t_config *config); /* UTILS */ long long get_utime(void); int verif_die_eating(t_philo *philo, t_only *only, t_config *config); int verif_finish(t_philo *philo, t_only *only); int finish(t_philo *philo, long long last_eat_time); void message_die(t_philo *philo, char *msg); void message(t_philo *philo, char *msg); int init_mutex(pthread_mutex_t *mutex, int nbr); void destroy_mutex(pthread_mutex_t *mutex, int nbr); int free_all(pthread_t *threads, t_same *same, t_philo **philo); int get_fork(t_philo *philo, int id_fork); void take_fork(t_philo *philo, int id_fork); void drop_fork(t_philo *philo, int id_fork, int next_id_fork); void ft_sleep(long long time_to_sleep); int *init_forks(t_config *config); int before_eat(t_philo *philo, t_only *only, t_config *config, int nbr_philo); int in_loop_eat_sleep(t_philo *philo, t_only *only, t_config *config, int nbr_philo); void wait_fork(t_philo *philo, t_only *only, int id); /* THREADS */ void *philosopher(t_philo *philo); #endif