You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* philosophers.h :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2021/11/24 15:44:06 by narnaud #+# #+# */
|
|
|
|
/* Updated: 2022/05/16 18:06:07 by narnaud ### ########.fr */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#ifndef PHILOSOPHERS_H
|
|
|
|
# define PHILOSOPHERS_H
|
|
|
|
# define CLOCK_ONE 500
|
|
|
|
# define CLOCK_TWO 1000
|
|
|
|
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
|
|
|
# include <pthread.h>
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
|
|
|
typedef struct s_param
|
|
|
|
{
|
|
|
|
int philo_amount;
|
|
|
|
int die_time;
|
|
|
|
int eat_duration;
|
|
|
|
int sleep_duration;
|
|
|
|
int eat_amount;
|
|
|
|
} t_param;
|
|
|
|
|
|
|
|
typedef struct s_philo
|
|
|
|
{
|
|
|
|
pthread_mutex_t *fork;
|
|
|
|
pthread_mutex_t *safe;
|
|
|
|
pthread_t *thd;
|
|
|
|
size_t eat_time;
|
|
|
|
int eat_amount;
|
|
|
|
int i;
|
|
|
|
} t_philo;
|
|
|
|
|
|
|
|
typedef struct s_room
|
|
|
|
{
|
|
|
|
t_param *param;
|
|
|
|
t_philo **philos;
|
|
|
|
pthread_mutex_t *safe;
|
|
|
|
int running;
|
|
|
|
int i;
|
|
|
|
} t_room;
|
|
|
|
|
|
|
|
//philo_threads.c
|
|
|
|
void *philos_life(void *r);
|
|
|
|
|
|
|
|
//philo_init.c
|
|
|
|
t_param *init_param(char **argv);
|
|
|
|
t_room *init_room(char **argv);
|
|
|
|
|
|
|
|
//philo_utils.c
|
|
|
|
int mini_atoi(char *nbr);
|
|
|
|
void safe_print(char *str, t_room *room, int id);
|
|
|
|
int clean_memory(t_room *room);
|
|
|
|
int safe_wait(t_room *room, size_t start, size_t duration);
|
|
|
|
size_t gettime(void);
|
|
|
|
|
|
|
|
#endif
|