debut implementation death tout est casse

This commit is contained in:
Hugo LAMY
2022-01-21 18:32:37 +01:00
parent be439700e9
commit 6a4aad9503
12 changed files with 107 additions and 214 deletions

22
srcs/message.c Normal file
View File

@@ -0,0 +1,22 @@
#include "philo.h"
void print_message(t_philo *philo, char *msg)
{
long int time_stamp;
struct timeval stime;
char *color;
gettimeofday(&stime, NULL);
time_stamp = (stime.tv_sec - philo->t_start_s) * 1000;
time_stamp += (stime.tv_usec - philo->t_start_u) / 1000;
color = WHITE;
if (ft_strnstr(msg, "eating", ft_strlen(msg)))
color = B_YELLOW;
if (ft_strnstr(msg, "sleeping", ft_strlen(msg)))
color = B_BLUE;
if (ft_strnstr(msg, "thinking", ft_strlen(msg)))
color = B_GREEN;
pthread_mutex_lock(philo->m_print);
ft_printf("%s%i %i %s%s\n", color, time_stamp, philo->p_nbr, msg, RESET);
pthread_mutex_unlock(philo->m_print);
}