put time.c and message.c into generic.c

This commit is contained in:
Hugo LAMY
2022-01-22 19:19:39 +01:00
parent cb615cb6b3
commit 82fef42d2a
4 changed files with 23 additions and 27 deletions

View File

@@ -24,8 +24,7 @@ LIBFT = $(LIBFT_D)/libft.a
SRCS = main.c \ SRCS = main.c \
init.c \ init.c \
exec.c \ exec.c \
time.c \ generic.c
message.c
DIR_OBJS = builds DIR_OBJS = builds
OBJS = $(SRCS:%.c=$(DIR_OBJS)/%.o) OBJS = $(SRCS:%.c=$(DIR_OBJS)/%.o)

View File

@@ -7,11 +7,9 @@ t_philo *init(int ac, char **av, pthread_t **id);
// exec.c // exec.c
void *philo_exec(void *arg); void *philo_exec(void *arg);
// time.c // generic.c
void init_time(t_philo *philo); void init_time(t_philo *philo);
void update_time(t_philo *philo); void update_time(t_philo *philo);
// message.c
void print_message(t_philo *philo, char *msg); void print_message(t_philo *philo, char *msg);
#endif #endif

View File

@@ -1,5 +1,26 @@
#include "philo.h" #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) void print_message(t_philo *philo, char *msg)
{ {
long int time_stamp; long int time_stamp;

View File

@@ -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;
}