-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.h
70 lines (64 loc) · 2.28 KB
/
header.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* header.h :+: :+: */
/* +:+ */
/* By: tblanker <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/06/28 17:22:30 by tblanker #+# #+# */
/* Updated: 2022/03/28 11:01:22 by tblanker ######## odam.nl */
/* */
/* ************************************************************************** */
# ifndef HEADER_H
# define HEADER_H
# include <stdio.h>
# include <stdlib.h>
# include <sys/time.h>
# include <unistd.h>
# include <pthread.h>
typedef struct s_philosopher
{
int threaded;
int id;
int time_since_meal;
int left;
int right;
int start;
int meals;
} t_philosopher;
typedef struct s_table
{
int finished_eating;
int funeral;
int n_philosophers;
int time_until_starve;
int eating_time;
int sleeping_time;
int number_of_meals;
t_philosopher *philo_list;
pthread_mutex_t *lock;
struct timeval time;
unsigned int start_sec;
long int start_usec;
int timestamp;
pthread_mutex_t sync_lock;
pthread_mutex_t check_lock;
pthread_mutex_t print_lock;
pthread_t *thread_list;
} t_table;
int check_if_done(t_table *table, t_philosopher *philo);
void check_if_die(t_table *table);
void put_error(char *error, int usage);
int validate_input(t_table *table, int ac, char **av);
int initialize(t_table *table);
void start_threading(t_table *table);
void eat(t_table *table, t_philosopher *philo);
void sleep_and_think(t_table *table, t_philosopher *philo);
void *check_pulse_rates(void *arg);
void check_stomach(t_table *table, t_philosopher *philo);
int get_timestamp(t_table *table);
void philo_print(char *message, t_table *table, t_philosopher *philo);
int get_philo_id(t_table *table);
long ft_atoi(const char *str);
int ft_strlen(const char *s);
# endif