「✏️」 norm: normed project.
This commit is contained in:
@ -6,12 +6,20 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/12 12:13:35 by adjoly #+# #+# */
|
/* Created: 2024/08/12 12:13:35 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/19 23:19:17 by adjoly ### ########.fr */
|
/* Updated: 2024/08/20 15:43:56 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "philo.h"
|
#include "philo.h"
|
||||||
|
|
||||||
|
bool unlock_death(t_philo *philo, uint8_t i)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(philo->check);
|
||||||
|
pthread_mutex_unlock(&philo[i].fork.left);
|
||||||
|
pthread_mutex_unlock(philo[i].fork.right);
|
||||||
|
return (print_death(&philo[i]));
|
||||||
|
}
|
||||||
|
|
||||||
bool philo_check(t_philo *philo, t_pdata data)
|
bool philo_check(t_philo *philo, t_pdata data)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
@ -22,19 +30,13 @@ bool philo_check(t_philo *philo, t_pdata data)
|
|||||||
eaten = 0;
|
eaten = 0;
|
||||||
while (i < data.philo_nbr)
|
while (i < data.philo_nbr)
|
||||||
{
|
{
|
||||||
|
|
||||||
gettimeofday(&t1, NULL);
|
gettimeofday(&t1, NULL);
|
||||||
pthread_mutex_lock(philo->check);
|
pthread_mutex_lock(philo->check);
|
||||||
if (get_time_in_ms(philo[i].eat, t1) > data.die_time + 1)
|
if (get_time_in_ms(philo[i].eat, t1) > data.die_time + 1)
|
||||||
{
|
return (unlock_death(philo, i));
|
||||||
pthread_mutex_unlock(philo->check);
|
|
||||||
pthread_mutex_unlock(&philo[i].fork.left);
|
|
||||||
pthread_mutex_unlock(philo[i].fork.right);
|
|
||||||
return (print_death(&philo[i]));
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(philo->check);
|
|
||||||
if (philo[i].meal_left == 0)
|
if (philo[i].meal_left == 0)
|
||||||
eaten++;
|
eaten++;
|
||||||
|
pthread_mutex_unlock(philo->check);
|
||||||
if (get_death(philo, RETURN))
|
if (get_death(philo, RETURN))
|
||||||
return (true);
|
return (true);
|
||||||
i++;
|
i++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/08 15:30:46 by adjoly #+# #+# */
|
/* Created: 2024/07/08 15:30:46 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/13 10:32:25 by adjoly ### ########.fr */
|
/* Updated: 2024/08/20 15:44:22 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -54,7 +54,6 @@ t_pdata meal_nb(char **av, t_pdata data)
|
|||||||
return (data);
|
return (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
t_pdata fill_pdata(char **av)
|
t_pdata fill_pdata(char **av)
|
||||||
{
|
{
|
||||||
t_pdata data;
|
t_pdata data;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/07 15:11:02 by adjoly #+# #+# */
|
/* Created: 2024/07/07 15:11:02 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 19:04:16 by adjoly ### ########.fr */
|
/* Updated: 2024/08/20 15:44:09 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ typedef struct s_philo
|
|||||||
pthread_mutex_t *check;
|
pthread_mutex_t *check;
|
||||||
} t_philo;
|
} t_philo;
|
||||||
|
|
||||||
typedef enum s_bool_death
|
typedef enum s_bool_death
|
||||||
{
|
{
|
||||||
RETURN = -1,
|
RETURN = -1,
|
||||||
FALSE,
|
FALSE,
|
||||||
|
Reference in New Issue
Block a user