-
Notifications
You must be signed in to change notification settings - Fork 0
/
philo.h
78 lines (58 loc) · 1.21 KB
/
philo.h
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
73
74
75
76
77
78
#ifndef PHILO_H
# define PHILO_H
# include <pthread.h>
# define SUCCESS 1
# define FAIL 0
# define INFINITY -999
# define TRUE 1
# define FALSE 0
# define ALIVE 1
# define DEAD 0
# define KILL_PROCESS 1
# define KEEP_PROCESS 0
typedef struct s_philo t_philo;
typedef struct s_rule
{
int num_of_philo;
int time_to_die;
int time_to_eat;
int time_to_sleep;
int count_of_must_eat;
int if_count_of_must_eat;
int is_dining;
} t_rule;
typedef struct s_param
{
long long start_time;
struct s_rule *rule;
pthread_mutex_t *forks;
pthread_t *tids;
t_philo *philo;
} t_param;
typedef struct s_philo
{
struct s_param *param;
int tid_index;
int life; //
int eat_count;
long long starving_time;
pthread_mutex_t *left_fork;
pthread_mutex_t *right_fork;
} t_philo;
/* ft_atoi.c */
int ft_is_digit(int c);
int ft_atoi(const char *str);
/* get_time.c */
long long get_time(void);
/* init_func.c */
int init_param(t_param *param, t_rule *rule);
/* monitoring.c */
int monitoring_philos(t_param param);
/* parsing.c */
int parsing(int argc, char **argv, t_rule *rule);
/* philo_act */
int philo_run(t_rule *rule);
// test
void test_print(t_rule rule);
void test_philo(t_philo philo, int i);
#endif