-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphilo.h
More file actions
88 lines (74 loc) · 2.56 KB
/
philo.h
File metadata and controls
88 lines (74 loc) · 2.56 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lrosch <lrosch@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/09 13:56:26 by lrosch #+# #+# */
/* Updated: 2022/01/26 16:44:07 by lrosch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# include <stdlib.h>
# include <stdio.h>
# include <limits.h>
# include <pthread.h>
# include <sys/time.h>
# include <unistd.h>
typedef struct s_input {
int nbr_philo;
int tt_die;
int tt_eat;
int tt_sleep;
int nbr_eat;
int waiting;
int death_flag;
int done;
int first;
struct timeval start_t;
pthread_mutex_t death_m;
pthread_mutex_t speak_m;
pthread_mutex_t waiting_m;
pthread_mutex_t done_m;
} t_input;
typedef struct s_philo {
struct s_input *input;
int index;
int done_eat;
long alive_t;
pthread_mutex_t *fork_l;
pthread_mutex_t *fork_r;
pthread_mutex_t philo_done_m;
} t_philo;
/* eat_sleep_repeat */
void philo_mutex_lock(t_philo *philo);
void philo_eat(t_philo *philo);
void philo_schleep(t_philo *philo);
int is_dead(t_philo *philo);
/* error_checking */
int error_checking(int argc, char **argv);
int ft_notint(char *s);
long long int ft_atoi(const char *str);
/* free */
void freeall(t_philo **all, pthread_t *philo, t_input *input);
void free_array(t_philo **all, t_input *input);
/* philo_initialize */
int init_input_m(t_input *input);
void init_philo(t_philo **all, int i, t_input *input);
int init_input(int argc, char **argv, t_input *input);
/* philo_utils */
long gettimestamp(t_philo *philo);
void printer(t_philo *philo, char *msg, int flag);
/* philo */
void routine(t_philo *philo);
void start_threads(t_philo **all, t_input *input, pthread_t *philo);
void death_check(t_philo **all, t_input *input);
void *thread_philo(void *args);
/* edge_cases */
int philo_one(t_philo *philo);
/* thread */
void *thread_philo(void *args);
void routine(t_philo *philo);
#endif