#-std=c99
NAME := philo
+INCDIR := .
SRCDIR := .
SRCS := main.c
+
SRCS := $(addprefix $(SRCDIR)/, $(SRCS))
OBJS := $(SRCS:%.c=%.o)
+CFLAGS += $(addprefix -I, $(INCDIR))
all : $(NAME)
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 12:49:40 by ljiriste #+# #+# */
-/* Updated: 2024/03/19 14:20:33 by ljiriste ### ########.fr */
+/* Updated: 2024/03/19 14:26:42 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
+#include "philo.h"
#include <stddef.h>
#include <stdlib.h>
#include <pthread.h>
static const char *g_die_str = "died";
// unsigned long would be more apropriate for min_eats_num
// but for the ease of parsing I'm using size_t
-typedef struct s_settings
-{
- int end;
- size_t min_eats_num;
- size_t philo_count;
- suseconds_t time_to_die;
- suseconds_t time_to_eat;
- suseconds_t time_to_sleep;
- suseconds_t program_start;
- pthread_mutex_t terminal;
-} t_settings;
-
-typedef struct s_philo
-{
- size_t times_eaten;
- size_t id;
- suseconds_t last_eaten;
- pthread_mutex_t *forks[2];
- t_settings *settings;
-} t_philo;
suseconds_t cur_time_sus(void)
{
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* philo.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/19 14:25:18 by ljiriste #+# #+# */
+/* Updated: 2024/03/19 14:33:17 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PHILO_H
+# define PHILO_H
+
+# include <stddef.h>
+# include <pthread.h>
+# include <sys/time.h>
+
+typedef struct s_settings
+{
+ int end;
+ size_t min_eats_num;
+ size_t philo_count;
+ suseconds_t time_to_die;
+ suseconds_t time_to_eat;
+ suseconds_t time_to_sleep;
+ suseconds_t program_start;
+ pthread_mutex_t terminal;
+} t_settings;
+
+typedef struct s_philo
+{
+ size_t times_eaten;
+ size_t id;
+ suseconds_t last_eaten;
+ pthread_mutex_t *forks[2];
+ t_settings *settings;
+} t_philo;
+
+#endif //PHILO_H