-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo_utils.c
56 lines (47 loc) · 1.57 KB
/
algo_utils.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
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rtavabil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/21 18:40:52 by rtavabil #+# #+# */
/* Updated: 2024/03/21 18:57:33 by rtavabil ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
void wait_all(t_args *args)
{
while (!get_bool(&args->args_mutex, &args->all_ready))
;
}
long get_long(t_philo *philo, long *value)
{
long ret;
ft_mutex(&philo->mutex, "lock");
ret = *value;
ft_mutex(&philo->mutex, "unlock");
return (ret);
}
int is_finished(t_args *args)
{
return (get_bool(&args->args_mutex, &args->end));
}
int get_bool(pthread_mutex_t *mutex, long int *value)
{
int ret;
ft_mutex(mutex, "lock");
ret = *value;
ft_mutex(mutex, "unlock");
return (ret);
}
int all_threads_run(t_args *args)
{
int ret;
ret = 1;
ft_mutex(&args->args_mutex, "lock");
if (args->num_phil == args->num_th)
ret = 0;
ft_mutex(&args->args_mutex, "unlock");
return (ret);
}