Start the refactor of this project
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 19 Mar 2024 13:35:36 +0000 (14:35 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 19 Mar 2024 13:35:36 +0000 (14:35 +0100)
philo/Makefile
philo/main.c
philo/philo.h [new file with mode: 0644]

index 1a6a0332c62bf46df121dea0445133ec611c26ff..22d66d364c074bcb135e1ec86083d3f408074725 100644 (file)
@@ -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)
 
index e32081da6a4cc0e3d756f5464c275e0e60ea415b..51415887c2ad2919cb334436ec5362716f835c26 100644 (file)
@@ -6,10 +6,11 @@
 /*   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>
@@ -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 (file)
index 0000000..868f2fe
--- /dev/null
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   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