-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphilosophers.h
More file actions
88 lines (82 loc) · 2.65 KB
/
Copy pathphilosophers.h
File metadata and controls
88 lines (82 loc) · 2.65 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philosophers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yaiba <yaiba@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/08 15:28:13 by melkarmi #+# #+# */
/* Updated: 2021/10/19 02:36:35 by yaiba ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILOSOPHERS_H
# define PHILOSOPHERS_H
# include <pthread.h>
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/time.h>
typedef struct s_fork
{
int philo;
int new_philo;
pthread_mutex_t flock;
struct s_fork *next;
} t_fork;
typedef struct s_data
{
int num_philos;
int time_todie;
int time_toeat;
int time_tosleep;
int meals;
int philo_id;
pthread_mutex_t lock;
pthread_mutex_t alive;
t_fork *fork;
int run;
long start_time;
} t_data;
typedef struct s_philo
{
int id;
int status;
int eatenmeals;
long die;
int fork;
int fork1;
pthread_t trd_id;
t_data *data;
struct s_philo *next;
} t_philo;
void check_isalive(t_philo *philo);
void ft_putstr(char *str, int fd);
int ft_strlen(char *str);
void log_data(t_philo *philo);
int ft_isdigit(int cc);
int ft_atoi(const char *s);
void init_data(t_data *data, char **av, int ac);
void init_mutex(t_data *data);
int check_args(char **av);
t_philo *create_philos(t_philo *philo, t_data *data);
t_philo *new_philo(int content, t_data *data);
t_fork *new_fork(int content);
void addback(t_philo **alst, t_philo *new);
void addbackf(t_fork **alst, t_fork *new);
void print(char *msg, t_philo *philo, long time, int a);
void ft_putnbr_fd(long n, int fd);
void ft_putchar_fd(char c, int i);
int log_error(char *err, int ret);
long get_time(void);
void sleep_thread(int time, t_philo *philo);
t_fork *get_fork(t_data *data, int philo_id);
int ready_to_eat(t_philo *philo);
void forks_down(t_philo *philo);
t_fork *get_fork(t_data *data, int philo_id);
void start_threads(t_philo *philos);
void *routine(void *tmp);
void free_all(t_philo **philo);
void log_died(t_philo *philo, t_data *data);
int check_errors(int ac, char **av);
#endif