From 82fef42d2a8770b80895afd4171d0bfb4baaa7b2 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sat, 22 Jan 2022 19:19:39 +0100 Subject: [PATCH] put time.c and message.c into generic.c --- Makefile | 3 +-- headers/philo_proto.h | 4 +--- srcs/{message.c => generic.c} | 21 +++++++++++++++++++++ srcs/time.c | 22 ---------------------- 4 files changed, 23 insertions(+), 27 deletions(-) rename srcs/{message.c => generic.c} (64%) delete mode 100644 srcs/time.c diff --git a/Makefile b/Makefile index c4f0d23..0a4a811 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,7 @@ LIBFT = $(LIBFT_D)/libft.a SRCS = main.c \ init.c \ exec.c \ - time.c \ - message.c + generic.c DIR_OBJS = builds OBJS = $(SRCS:%.c=$(DIR_OBJS)/%.o) diff --git a/headers/philo_proto.h b/headers/philo_proto.h index dfef26e..0bc73b1 100644 --- a/headers/philo_proto.h +++ b/headers/philo_proto.h @@ -7,11 +7,9 @@ t_philo *init(int ac, char **av, pthread_t **id); // exec.c void *philo_exec(void *arg); -// time.c +// generic.c void init_time(t_philo *philo); void update_time(t_philo *philo); - -// message.c void print_message(t_philo *philo, char *msg); #endif diff --git a/srcs/message.c b/srcs/generic.c similarity index 64% rename from srcs/message.c rename to srcs/generic.c index 52e8b31..777ac95 100644 --- a/srcs/message.c +++ b/srcs/generic.c @@ -1,5 +1,26 @@ #include "philo.h" +void init_time(t_philo *philo) +{ + struct timeval stime; + + if (philo->global->t_start_s == 0) + { + gettimeofday(&stime, NULL); + philo->global->t_start_s = stime.tv_sec; + philo->global->t_start_u = stime.tv_usec; + } +} + +void update_time(t_philo *philo) +{ + struct timeval stime; + + gettimeofday(&stime, NULL); + philo->t_last_meal_s = stime.tv_sec; + philo->t_last_meal_u = stime.tv_usec; +} + void print_message(t_philo *philo, char *msg) { long int time_stamp; diff --git a/srcs/time.c b/srcs/time.c deleted file mode 100644 index 92a42de..0000000 --- a/srcs/time.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "philo.h" - -void init_time(t_philo *philo) -{ - struct timeval stime; - - if (philo->global->t_start_s == 0) - { - gettimeofday(&stime, NULL); - philo->global->t_start_s = stime.tv_sec; - philo->global->t_start_u = stime.tv_usec; - } -} - -void update_time(t_philo *philo) -{ - struct timeval stime; - - gettimeofday(&stime, NULL); - philo->t_last_meal_s = stime.tv_sec; - philo->t_last_meal_u = stime.tv_usec; -}