-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_philo.c
More file actions
72 lines (62 loc) · 2.22 KB
/
Copy pathcheck_philo.c
File metadata and controls
72 lines (62 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_philo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thuy-ngu <thuy-ngu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/13 16:37:20 by thuy-ngu #+# #+# */
/* Updated: 2024/09/13 16:37:20 by thuy-ngu ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
size_t count_meal_nbr(t_philo *philo, int function)
{
bool done;
done = false;
pthread_mutex_lock(&(philo->nbr_eat_mutex));
if (function == CHANGE)
philo->nbr_eat += 1;
if ((philo->nbr_eat) == (philo->info->limitnbr_eat))
done = true;
pthread_mutex_unlock(&(philo->nbr_eat_mutex));
return (done);
}
size_t set_last_meal(t_philo *philo, int function)
{
size_t last_meal_time;
last_meal_time = 0;
pthread_mutex_lock(&philo->last_meal_mutex);
if (function == CHANGE)
philo->last_meal = get_time();
last_meal_time = philo->last_meal;
pthread_mutex_unlock(&philo->last_meal_mutex);
return (last_meal_time);
}
int check_status(t_philo *philo)
{
int status;
pthread_mutex_lock(&philo->status_mutex);
status = philo->status;
pthread_mutex_unlock(&philo->status_mutex);
return (status);
}
void set_status(t_philo *philo, int status)
{
pthread_mutex_lock(&philo->status_mutex);
if (philo->status != DEAD)
philo->status = status;
pthread_mutex_unlock(&philo->status_mutex);
}
bool set_dead_bool(t_philo *philo, int function)
{
bool one_died;
one_died = false;
pthread_mutex_lock(&philo->dead_bool_mutex);
if (function == CHANGE)
philo->dead = true;
if (philo->dead)
one_died = true;
pthread_mutex_unlock(&philo->dead_bool_mutex);
return (one_died);
}