-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_utils2.c
53 lines (47 loc) · 1.84 KB
/
thread_utils2.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* thread_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wlalaoui <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 16:13:50 by wlalaoui #+# #+# */
/* Updated: 2024/01/12 16:45:13 by wlalaoui ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
void increase_ate_count(t_philo *data)
{
pthread_mutex_lock(&data->ate_mutex);
data->ate_c++;
pthread_mutex_unlock(&data->ate_mutex);
}
void assign_currtime(t_philo *data)
{
pthread_mutex_lock(&data[0].currtime_mutex);
data[0].curr_time = cur_t();
pthread_mutex_unlock(&data[0].currtime_mutex);
}
void assign_isphilodead(t_data *d, bool value)
{
pthread_mutex_lock(&d->args.dead_mutex);
d->args.is_one_philo_dead = value;
pthread_mutex_unlock(&d->args.dead_mutex);
}
void assign_false_ifdidntfullyate(t_data *d, bool *all_philo_ate,
size_t i, int argc)
{
pthread_mutex_lock(&d->ph_l[i].ate_mutex);
if (argc == 6 && d->args.eat_c > d->ph_l[i].ate_c)
*all_philo_ate = false;
pthread_mutex_unlock(&d->ph_l[i].ate_mutex);
}
int trigger_die_event(t_data *d, size_t i, pthread_t *th)
{
pthread_mutex_unlock(&d->ph_l[i].currtime_mutex);
assign_isphilodead(d, true);
printf_die(d, i);
if (!join_threads(th, d->args.list_length))
return (1);
return (0);
}