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