philosopher/philo/utils_threads3.c
Etienne Rey-bethbeder 140889a1fd _
2023-04-10 17:39:30 +02:00

40 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_threads3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 10:39:43 by erey-bet #+# #+# */
/* Updated: 2023/04/10 10:39:56 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
void ft_sleep(long long time_to_sleep)
{
if (time_to_sleep < 0)
return ;
usleep(time_to_sleep);
}
int before_eat(t_philo *philo, t_only *only,
t_config *config, int nbr_philo)
{
if (verif_finish(philo, only))
return (0);
take_fork(philo, only->next_id);
message(philo, "has taken a fork\n");
message(philo, "is eating\n");
if (!in_loop_eat_sleep(philo, only, config, nbr_philo))
return (0);
return (1);
}
void wait_fork(t_philo *philo, t_only *only, int id)
{
while (!finish(philo, only->last_eat_time) && !get_fork(philo, id))
;
}