78 lines
2.1 KiB
C
78 lines
2.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* philo.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/03/08 14:51:16 by erey-bet #+# #+# */
|
|
/* Updated: 2023/03/31 17:47:02 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef PHILO_H
|
|
# define PHILO_H
|
|
|
|
# include "../utils/utils.h"
|
|
# include <stdlib.h>
|
|
# include <unistd.h>
|
|
# include <pthread.h>
|
|
# include <sys/wait.h>
|
|
# include <sys/time.h>
|
|
# include <pthread.h>
|
|
# include <stdio.h>
|
|
|
|
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;
|
|
pthread_mutex_t *mutex;
|
|
int *all_eat;
|
|
int *death;
|
|
|
|
} t_same;
|
|
|
|
typedef struct s_only
|
|
{
|
|
int id;
|
|
int next_id;
|
|
long long time;
|
|
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(long long time, int id, char *msg);
|
|
void init_mutex(pthread_mutex_t *mutex, int nbr);
|
|
void destroy_mutex(pthread_mutex_t *mutex, int nbr);
|
|
void free_all(pthread_t *threads, t_same *same, t_philo **philo);
|
|
|
|
/* THREADS */
|
|
void *philosopher(t_philo *philo);
|
|
|
|
#endif
|