From: Lukas Jiriste Date: Tue, 19 Mar 2024 13:35:36 +0000 (+0100) Subject: Start the refactor of this project X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=b3e9e47edf2caced9053d2bf44183d0f73096b3f;p=42%2Fphilosophers_old.git Start the refactor of this project --- diff --git a/philo/Makefile b/philo/Makefile index 1a6a033..22d66d3 100644 --- a/philo/Makefile +++ b/philo/Makefile @@ -4,10 +4,13 @@ CFLAGS := -Wall -Wextra -Werror -Wpedantic #-std=c99 NAME := philo +INCDIR := . SRCDIR := . SRCS := main.c + SRCS := $(addprefix $(SRCDIR)/, $(SRCS)) OBJS := $(SRCS:%.c=%.o) +CFLAGS += $(addprefix -I, $(INCDIR)) all : $(NAME) diff --git a/philo/main.c b/philo/main.c index e32081d..5141588 100644 --- a/philo/main.c +++ b/philo/main.c @@ -6,10 +6,11 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 #include #include @@ -25,26 +26,6 @@ static const char *g_sleep_str = "is sleeping"; 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) { diff --git a/philo/philo.h b/philo/philo.h new file mode 100644 index 0000000..868f2fe --- /dev/null +++ b/philo/philo.h @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* philo.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include + +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