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.

68 lines
1.9 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
3 years ago
/* philo.h :+: :+: :+: */
3 years ago
/* +:+ +:+ +:+ */
3 years ago
/* By: narnaud@student.42nice.fr <marvin@42.fr> +#+ +:+ +#+ */
3 years ago
/* +#+#+#+#+#+ +#+ */
3 years ago
/* Created: 2022/05/18 22:23:52 by narnaud@stude #+# #+# */
3 years ago
/* Updated: 2022/05/20 10:29:02 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
3 years ago
#ifndef PHILO_H
# define PHILO_H
3 years ago
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <pthread.h>
# include <sys/time.h>
3 years ago
enum e_params
{
3 years ago
PHILO_AMOUNT,
DIE_TIME,
EAT_DURATION,
SLEEP_DURATION,
MEALS_AMOUNT,
};
3 years ago
3 years ago
typedef struct s_room
{
int param[5];
pthread_mutex_t *lock;
pthread_mutex_t *forks;
int running;
} t_room;
3 years ago
typedef struct s_philo
{
3 years ago
t_room *room;
3 years ago
pthread_mutex_t *fork;
3 years ago
pthread_mutex_t *fork_r;
pthread_mutex_t *next;
3 years ago
pthread_mutex_t *lock;
3 years ago
pthread_t *thd;
3 years ago
int eat_time;
3 years ago
int eat_amount;
3 years ago
int id;
3 years ago
} t_philo;
3 years ago
// ---------------------------------- philo_init
t_room *create_room(char **argv);
t_philo *create_philos(t_room *room);
void invit_philos(t_philo *philos);
3 years ago
3 years ago
// ---------------------------------- philo_life
void *philos_life(void *r);
3 years ago
3 years ago
// ---------------------------------- philo_utils
3 years ago
int safe_print(t_philo *philo, char *str);
int safe_wait(t_room *room, int start, int duration);
int room_clock(void);
int mini_atoi(char *nbr);
3 years ago
#endif