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.
61 lines
1.6 KiB
61 lines
1.6 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* philosophers.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/11/24 15:44:06 by narnaud #+# #+# */
|
|
/* Updated: 2022/05/18 17:56:38 by narnaud@stude ### ########.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>
|
|
|
|
enum e_params
|
|
{
|
|
PHILO_AMOUNT,
|
|
DIE_TIME,
|
|
EAT_DURATION,
|
|
SLEEP_DURATION,
|
|
MEALS_AMOUNT,
|
|
};
|
|
|
|
typedef struct s_philo
|
|
{
|
|
pthread_mutex_t *fork;
|
|
pthread_mutex_t *lock;
|
|
pthread_t *thd;
|
|
int eat_time;
|
|
int eat_amount;
|
|
int i;
|
|
} t_philo;
|
|
|
|
typedef struct s_room
|
|
{
|
|
int param[5];
|
|
t_philo **philos;
|
|
pthread_mutex_t *lock;
|
|
int running;
|
|
int i;
|
|
} t_room;
|
|
|
|
int waiter(t_room *room);
|
|
|
|
void *philos_birth(void *r);
|
|
|
|
int safe_print(char *str, t_room *room, int id);
|
|
int safe_wait(t_room *room, int start, int duration);
|
|
int room_clock();
|
|
|
|
#endif
|
|
|