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.

57 lines
2.0 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/08/13 10:22:30 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
2024-08-12 20:52:02 +02:00
bool print_err(uint8_t error)
{
if (error == 0)
printf(ERR_MAX_PHIL);
else if (error == 1)
printf(ERR_MAX_DIE_TIME);
else if (error == 2)
printf(ERR_MAX_EAT_TIME);
else if (error == 3)
printf(ERR_MAX_SLEEP_TIME);
else if (error == 4)
printf(ERR_MAX_MEAL);
else if (error == 5)
printf(ERR_NB_ARG);
else if (error == 6)
printf(ERR_ARG);
2024-08-12 20:52:02 +02:00
return (true);
}
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);
pthread_mutex_lock(&print);
2024-08-12 20:52:02 +02:00
timestamp = get_time_in_ms(philo->t0, t1);
if (philo->state == EAT)
printf("%u %hu %s", timestamp, philo->id, EATING_MSG);
else if (philo->state == THINK)
printf("%u %hu %s", timestamp, philo->id, THINK_MSG);
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);
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
}