1
0
This commit is contained in:
2024-07-22 13:14:10 +02:00
parent b706482b26
commit 5686d00f61
3 changed files with 22 additions and 18 deletions

View File

@ -6,7 +6,7 @@
/* 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 */
/* Updated: 2024/07/21 21:31:44 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,15 +19,15 @@ void log_philo(uint32_t timestamp, t_philo philo)
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);
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);
}

View File

@ -1,17 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_argv.c :+: :+: :+: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:30:46 by adjoly #+# #+# */
/* Updated: 2024/07/09 10:46:47 by adjoly ### ########.fr */
/* Updated: 2024/07/21 21:23:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
#include "utils.h"
t_pdata fill_pdata(char **av)
{

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 15:11:02 by adjoly #+# #+# */
/* Updated: 2024/07/18 18:30:56 by adjoly ### ########.fr */
/* Updated: 2024/07/21 21:55:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -53,18 +53,23 @@ typedef struct s_philo
t_fork fork;
t_pstate state;
t_pdata data;
pthread_t thread;
} t_philo;
typedef struct s_init
{
pthread_t thread;
t_philo data;
} t_init;
/**
* Utils
*/
void log_philo(uint32_t timestamp, uint16_t philo, t_pstate type);
void log_philo(uint32_t timestamp, t_philo philo);
t_pdata philo_parse(char **argv, int ac);
long long ft_atoll(const char *nptr);
uint16_t get_time_in_ms(struct timeval t0, struct timeval t1);
void *philo_routine(void *param)
void *philo_routine(void *param);
/**
* Main path
* by order of call