1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.

38 lines
1.6 KiB
C
Raw Normal View History

2024-07-08 10:33:28 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* log.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 16:12:20 by adjoly #+# #+# */
/* Updated: 2024/07/24 23:56:07 by adjoly ### ########.fr */
2024-07-08 10:33:28 +02:00
/* */
/* ************************************************************************** */
#include "philo.h"
#include "philo_msg.h"
#include <stdio.h>
2024-07-08 10:33:28 +02:00
void log_philo(t_philo philo)
2024-07-08 10:33:28 +02:00
{
uint32_t timestamp;
struct timeval t1;
static pthread_mutex_t print = {0};
gettimeofday(&t1, NULL);
timestamp = get_time_in_ms(philo.t0, t1);
pthread_mutex_lock(&print);
2024-07-22 13:14:10 +02:00
if (philo.state == EAT)
printf("%u %hu %s", timestamp, philo.id, EATING_MSG);
2024-07-22 13:14:10 +02:00
else if (philo.state == THINK)
printf("%u %hu %s", timestamp, philo.id, THINK_MSG);
2024-07-22 13:14:10 +02:00
else if (philo.state == SLEEP)
printf("%u %hu %s", timestamp, philo.id, SLEEP_MSG);
else if (philo.state == DEAD)
printf("%u %hu %s", timestamp, philo.id, DIED_MSG);
2024-07-22 13:14:10 +02:00
else if (philo.state == FORK_TAKEN)
printf("%u %hu %s", timestamp, philo.id, FORK_MSG);
pthread_mutex_unlock(&print);
2024-07-08 10:33:28 +02:00
}