-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphilo.h
81 lines (68 loc) · 2.18 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
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: muerdoga <muerdoga@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/31 15:02:17 by muerdoga #+# #+# */
/* Updated: 2023/02/10 15:54:42 by muerdoga ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# include <sys/time.h>
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <pthread.h>
typedef struct s_philosopher
{
int id;
int x_ate;
int left_fork_id;
int right_fork_id;
long long t_last_meal;
struct s_rules *rules;
pthread_t thread_id;
} t_philosopher;
typedef struct s_rules
{
int nb_philo;
int time_death;
int time_eat;
int time_sleep;
int nb_eat;
int dieded;
int all_ate;
long long first_timestamp;
pthread_mutex_t meal_check;
pthread_mutex_t forks[250];
pthread_mutex_t writing;
t_philosopher philosophers[250];
} t_rules;
/*
** ----- error_manager.c -----
*/
int write_error(char *str);
int error_manager(int error);
void eat_control(t_rules *r, t_philosopher *p);
/*
** ----- init.c -----
*/
int init_all(t_rules *rules, char **argv);
/*
** ----- utils.c -----
*/
int ft_atoi(const char *str);
void action_print(t_rules *rules, int id, char *string);
long long timestamp(void);
long long time_diff(long long past, long long pres);
void smart_sleep(long long time, t_rules *rules);
/*
** ----- launcher.c -----
*/
int launcher(t_rules *rules);
void exit_launcher(t_rules *rules, t_philosopher *philos);
#endif