messages en couleurs
This commit is contained in:
25
srcs/exec.c
25
srcs/exec.c
@@ -2,8 +2,22 @@
|
||||
|
||||
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("%i %s\n", philo->p_nbr, msg);
|
||||
ft_printf("%s%i %i %s%s\n", color, time_stamp, philo->p_nbr, msg, RESET);
|
||||
pthread_mutex_unlock(philo->m_print);
|
||||
}
|
||||
|
||||
@@ -23,12 +37,10 @@ void init_time(t_philo *philo)
|
||||
void update_time(t_philo *philo)
|
||||
{
|
||||
struct timeval stime;
|
||||
// long int time_stamp;
|
||||
|
||||
gettimeofday(&stime, NULL);
|
||||
philo->t_last_meal_s = stime.tv_sec;
|
||||
philo->t_last_meal_u = stime.tv_usec;
|
||||
// time_stamp = (stime.tv_sec - scd) * 1000 + (stime.tv_usec - mcr) / 1000;
|
||||
}
|
||||
|
||||
void take_forks(t_philo *philo)
|
||||
@@ -45,11 +57,6 @@ void take_forks(t_philo *philo)
|
||||
pthread_mutex_unlock(&(philo->m_fork));
|
||||
}
|
||||
|
||||
// print_message(philo, "has taken a fork");
|
||||
// print_message(philo, "is eating");
|
||||
// print_message(philo, "is thinking");
|
||||
// print_message(philo, "is sleeping");
|
||||
//
|
||||
// int n_phi; // number_of_philosophers
|
||||
// int t_die; // time_to_die
|
||||
// int t_eat; // time_to_eat
|
||||
@@ -69,7 +76,7 @@ void *philo_exec(void *arg)
|
||||
|
||||
print_message(philo, "is sleeping");
|
||||
usleep(philo->params->t_slp * 1000);
|
||||
print_message(philo, "is sleeping");
|
||||
print_message(philo, "is thinking");
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user