aboutsummaryrefslogtreecommitdiff
path: root/philo_one
diff options
context:
space:
mode:
Diffstat (limited to 'philo_one')
-rw-r--r--philo_one/Makefile38
-rw-r--r--philo_one/main.c26
-rw-r--r--philo_one/philo_one.h41
3 files changed, 105 insertions, 0 deletions
diff --git a/philo_one/Makefile b/philo_one/Makefile
new file mode 100644
index 0000000..0c9125c
--- /dev/null
+++ b/philo_one/Makefile
@@ -0,0 +1,38 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2019/11/24 05:50:15 by cacharle #+# #+# #
+# Updated: 2019/11/24 07:07:35 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
+RM = rm -f
+
+CC = gcc
+CCFLAGS = -Wall -Wextra #-Werror
+LDFLAGS = -lpthread
+
+NAME = philo_one
+SRC = main.c
+OBJ = $(SRC:.c=.o)
+
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ $(CC) $(LDFLAGS) -o $@ $(OBJ)
+
+%.o: %.c
+ $(CC) $(CCFLAGS) -c -o $@ $^
+
+clean:
+ $(RM) $(OBJ)
+
+fclean: clean
+ $(RM) $(NAME)
+
+re: fclean all
diff --git a/philo_one/main.c b/philo_one/main.c
new file mode 100644
index 0000000..3bb1181
--- /dev/null
+++ b/philo_one/main.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */
+/* Updated: 2019/11/24 06:35:10 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "philo_one.h"
+
+int main(int argc, char **argv)
+{
+ if (argc != 5 || argc != 6)
+ return (1);
+ int philo_nb = ft_atoi(argv[1]);
+ int death_timer = ft_atoi(argv[2]);
+ int eat_timer = ft_atoi(argv[3]);
+ int sleep_timer = ft_atoi(argv[4]);
+ if (argc == 6)
+ int eat_nb = ft_atoi(argv[5]);
+ return (0);
+}
diff --git a/philo_one/philo_one.h b/philo_one/philo_one.h
new file mode 100644
index 0000000..4bf9d14
--- /dev/null
+++ b/philo_one/philo_one.h
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* philo_one.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/24 06:11:16 by cacharle #+# #+# */
+/* Updated: 2019/11/24 06:55:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PHILO_ONE
+# define PHILO_ONE
+
+# include <unistd.h>
+# include <sys/time.h>
+# include <stdlib.h>
+
+typedef enum
+{
+ STATE_EATING,
+ STATE_THINKING,
+ STATE_SLEEPING,
+ STATE_TOOK_FORK,
+ STATE_DEAD
+} t_philo_state;
+
+
+typedef struct
+{
+ int id;
+ t_philo_state state;
+ t_bool alive;
+ int forks[2];
+ int finished_time;
+} t_philo
+
+void print_state_change(int timestamp, t_philo_state state);
+
+#endif