diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-09 03:33:24 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-09 03:33:24 +0100 |
| commit | dfbafce6506fe5c47b0e60289a9d4629e502c9ac (patch) | |
| tree | bff26d329d67b4d5f4f74dff4099743836ac8efb /common/common.h | |
| parent | 34058c2901f18fd11a6e50e9fa8e3faefdcc6c7b (diff) | |
| download | philosophers-dfbafce6506fe5c47b0e60289a9d4629e502c9ac.tar.gz philosophers-dfbafce6506fe5c47b0e60289a9d4629e502c9ac.tar.bz2 philosophers-dfbafce6506fe5c47b0e60289a9d4629e502c9ac.zip | |
Added common files
Diffstat (limited to 'common/common.h')
| -rw-r--r-- | common/common.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/common/common.h b/common/common.h new file mode 100644 index 0000000..ff371a9 --- /dev/null +++ b/common/common.h @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* common.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 22:58:35 by cacharle #+# #+# */ +/* Updated: 2020/02/09 03:22:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COMMON_H +# define COMMON_H + +# include <stdlib.h> +# include <sys/time.h> + +# define FALSE 0 +# define TRUE 1 + +typedef int t_bool; + +typedef enum +{ + PSTATE_EATING = 0, + PSTATE_SLEEPING, + PSTATE_THINKING, + PSTATE_NUM +} t_philo_state; + +typedef enum +{ + EVENT_FORK, + EVENT_EATING, + EVENT_SLEEPING, + EVENT_THINKING, + EVENT_DIED +} t_philo_event; + +typedef struct +{ + int id; + t_philo_state state; + pthread_t thread; +} t_philo; + +typedef struct +{ + int philo_num; + int timeout_death; + int timeout_eat; + int timeout_sleep; + int meal_num; +} t_philo_args; + +typedef void (*t_philo_routine)(void *arg); + +typedef struct +{ + t_bool used; + t_philo *left; + t_philo *right; +} t_fork; + +/* +** common.c +*/ + +t_bool parse_args(t_philo_args *philo_args, int argc, char **argv); +void philo_put_state_change(t_philo *philo, t_philo_event event); + +/* +** philo.c +*/ + +t_philo *philos_new(int num); +void philos_destroy(t_philo *philo); + +void philo_eat(t_philo *philo); +void philo_sleep(t_philo *philo); +void philo_think(t_philo *philo); + +/* +** helper.c +*/ + +int h_strtoposint(char *s); +int h_strlen(char *s); +void h_putnbr(unsigned long num); +void h_putchar(char c); +void h_putstr(char *s); +void *h_calloc(int count, int size); + + +#endif |
