Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo/philosophers.h
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* philosophers.h :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/19 23:37:56 by yabtaour #+# #+# */
9
/* Updated: 2022/05/19 23:39:37 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#ifndef PHILOSOPHERS_H
13
# define PHILOSOPHERS_H
14
15
# include <stdio.h>
16
# include <unistd.h>
17
# include <stdlib.h>
18
# include <string.h>
19
# include <pthread.h>
20
# include <sys/time.h>
21
22
typedef struct s_philo{
23
int philo_id;
24
int eat;
25
long long last_meal;
26
pthread_mutex_t *left_fork;
27
pthread_mutex_t *right_fork;
28
pthread_t thread_id;
29
struct s_data *data;
30
} t_philo;
31
32
typedef struct s_data{
33
int argc;
34
char **argv;
35
int philos_num;
36
int time_to_die;
37
int time_to_eat;
38
int time_to_sleep;
39
int must_eat;
40
int is_dead;
41
int all_ate;
42
long long birth;
43
char *args;
44
char **arguments;
45
t_philo philosopher[200];
46
int total;
47
long long time;
48
long long norm;
49
long long norm2;
50
t_philo *n;
51
pthread_mutex_t eat;
52
pthread_mutex_t fork[200];
53
pthread_mutex_t output;
54
} t_data;
55
56
char *ft_join_args(char *argv[], int argc);
57
void free_split(char **arguments);
58
int ft_strlen(char *str);
59
char *ft_substr(char *s, int start, size_t len);
60
void *ft_calloc(int count, int size);
61
char **ft_split(char *s, char c);
62
void ft_check_char(char **arguments);
63
int ft_atoi(const char *str);
64
void ft_start(t_data *data);
65
void ft_output(t_data *data, int philo_id, char *str);
66
long long ft_timestamp(void);
67
void ft_sleep(long long time, t_data *data);
68
void ft_eat(t_philo *philosopher);
69
int ft_check_dead(t_data *data);
70
int ft_parsing(t_data *data);
71
int ft_initialize_data(t_data *data);
72
int ft_start_mutex(t_data *data);
73
void ft_initialize_philosophers(t_data *data);
74
int ft_create_philosophers(t_data *data);
75
void *routine(void *data);
76
int ft_d(int c);
77
78
#endif
79
80