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.

34 lines
1.5 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/16 20:24:43 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(uint32_t timestamp, t_philo philo)
2024-07-08 10:33:28 +02:00
{
static pthread_mutex_t print = {0};
pthread_mutex_lock(&print);
if (philo->state == EAT)
printf("%u %hu %s", timestamp, philo->nbr, EATING_MSG);
else if (philo->state == THINK)
printf("%u %hu %s", timestamp, philo->nbr, THINK_MSG);
else if (philo->state == SLEEP)
printf("%u %hu %s", timestamp, philo->nbr, SLEEP_MSG);
else if (philo->state == DIED)
printf("%u %hu %s", timestamp, philo->nbr, DIED_MSG);
else if (philo->state == FORK_TAKEN)
printf("%u %hu %s", timestamp, philo->nbr, FORK_MSG);
pthread_mutex_unlock(&print);
2024-07-08 10:33:28 +02:00
}