narnaud
3 years ago
5 changed files with 133 additions and 55 deletions
@ -0,0 +1,26 @@ |
|||||
|
NAME = philo |
||||
|
|
||||
|
SRCS = philo.c philo_utils.c |
||||
|
OBJS = ${SRCS:.c=.o} |
||||
|
|
||||
|
CC = clang |
||||
|
CFLAGS = -Werror -Wextra -Wall -D_REENTRANT |
||||
|
RM = rm -rf |
||||
|
|
||||
|
%.o : %.c |
||||
|
$(CC) $(CFLAGS) -c $< -o $(<:.c=.o) |
||||
|
|
||||
|
all : $(NAME) |
||||
|
|
||||
|
$(NAME) : $(OBJS) |
||||
|
$(CC) $(CFLAGS) -lpthread $(OBJS) -o $(NAME) |
||||
|
|
||||
|
clean : |
||||
|
$(RM) $(OBJS) |
||||
|
|
||||
|
fclean : clean |
||||
|
$(RM) $(NAME) |
||||
|
|
||||
|
re : fclean all |
||||
|
|
||||
|
.PHONY : all clean fclean re |
@ -0,0 +1,64 @@ |
|||||
|
/* ************************************************************************** */ |
||||
|
/* */ |
||||
|
/* ::: :::::::: */ |
||||
|
/* philo.h :+: :+: :+: */ |
||||
|
/* +:+ +:+ +:+ */ |
||||
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
||||
|
/* +#+#+#+#+#+ +#+ */ |
||||
|
/* Created: 2022/05/16 14:03:01 by narnaud #+# #+# */ |
||||
|
/* Updated: 2022/05/20 09:26:20 by narnaud ### ########.fr */ |
||||
|
/* */ |
||||
|
/* ************************************************************************** */ |
||||
|
|
||||
|
#ifndef PHILOSOPHERS_H |
||||
|
# define PHILOSOPHERS_H |
||||
|
|
||||
|
# include <unistd.h> |
||||
|
# include <stdio.h> |
||||
|
# include <stdlib.h> |
||||
|
# include <pthread.h> |
||||
|
# include <string.h> |
||||
|
# include <errno.h> |
||||
|
# include <fcntl.h> |
||||
|
# include <signal.h> |
||||
|
# include <sys/wait.h> |
||||
|
# include <sys/time.h> |
||||
|
# include <sys/stat.h> |
||||
|
# include <semaphore.h> |
||||
|
|
||||
|
enum e_params |
||||
|
{ |
||||
|
PHILO_AMOUNT, |
||||
|
DIE_TIME, |
||||
|
EAT_DURATION, |
||||
|
SLEEP_DURATION, |
||||
|
MEALS_AMOUNT, |
||||
|
}; |
||||
|
|
||||
|
typedef struct s_table t_table; |
||||
|
|
||||
|
typedef struct s_philo |
||||
|
{ |
||||
|
int id; |
||||
|
size_t meals_done; |
||||
|
int last_meal_time; |
||||
|
t_table *table; |
||||
|
} t_philo; |
||||
|
|
||||
|
typedef struct s_table |
||||
|
{ |
||||
|
int param[5]; |
||||
|
int i; |
||||
|
sem_t *sptr; |
||||
|
sem_t *death; |
||||
|
t_philo *philos; |
||||
|
int time; |
||||
|
int *pid; |
||||
|
} t_table; |
||||
|
|
||||
|
/***************************/ |
||||
|
|
||||
|
t_table *parsing(char **argv); |
||||
|
int gettime(void); |
||||
|
|
||||
|
#endif |
Loading…
Reference in new issue