1
0

」 feat: nearly working to_do: implement all philo eat

This commit is contained in:
2024-08-08 18:48:47 +02:00
parent dde531f8dd
commit ec9ee12c29
12 changed files with 149 additions and 174 deletions

37
philo/eat.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* eat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 17:29:51 by adjoly #+# #+# */
/* Updated: 2024/08/08 18:05:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
bool philo_eat(t_philo *philo)
{
philo->state = FORK_TAKEN;
take_fork(&philo->fork, philo->id);
if (get_death(false, true, philo))
return (true);
log_philo(philo);
if (&(philo->fork.left) == philo->fork.right)
return (true);
take_fork(&philo->fork, philo->id + 1);
if (get_death(false, true, philo))
return (true);
log_philo(philo);
philo->state = EAT;
gettimeofday(&(philo->eat), NULL);
log_philo(philo);
if (sleep_phil(philo) == true)
return (true);
pthread_mutex_unlock(&philo->fork.left);
pthread_mutex_unlock(philo->fork.right);
philo->meal_left--;
return (false);
}