42 school project
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.
 
 

67 lines
1.9 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud@student.42nice.fr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/18 22:23:52 by narnaud@stude #+# #+# */
/* Updated: 2022/05/19 00:42:59 by narnaud@stude ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# 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_room
{
int param[5];
pthread_mutex_t *lock;
pthread_mutex_t *forks;
int running;
} t_room;
typedef struct s_philo
{
t_room *room;
pthread_mutex_t *fork;
pthread_mutex_t *fork_r;
pthread_mutex_t *next;
pthread_mutex_t *lock;
pthread_t *thd;
int eat_time;
int eat_amount;
int id;
} t_philo;
// ---------------------------------- philo_init
t_room *create_room(char **argv);
t_philo *create_philos(t_room *room);
void invit_philos(t_philo *philos);
// ---------------------------------- philo_life
void *philos_life(void *r);
// ---------------------------------- philo_utils
int safe_print(t_philo *philo, char *str);
int safe_wait(t_room *room, int start, int duration);
int room_clock();
int mini_atoi(char *nbr);
#endif