-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
70 lines (63 loc) · 2.12 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gichlee <gichlee@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/19 14:17:57 by gichlee #+# #+# */
/* Updated: 2023/08/04 15:29:19 by gichlee ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAIN_H
# define MAIN_H
# include <stdio.h>
# include <pthread.h>
# include <unistd.h>
# include <stdlib.h>
# include <sys/time.h>
# define TRUE 1
# define FALSE 0
typedef struct s_status
{
int total_phil;
int time_to_die;
int time_to_eat;
int time_to_sleep;
int num_must_eat;
int is_limit;
int finished_phil;
pthread_t *phil_threads;
pthread_mutex_t *forks;
int *forks_i;
int is_dead;
pthread_mutex_t m_print;
pthread_mutex_t m_dead;
pthread_mutex_t m_last_meal;
pthread_mutex_t m_finished_phil;
} t_status;
typedef struct s_phil
{
int phil_num;
size_t start;
size_t last_meal;
int count_eat;
struct s_status *s;
} t_phil;
void count_eating(t_phil *p);
int check_dead(t_phil *p);
t_phil **malloc_phil_arr(t_status **status);
int print(t_phil *p, char *msg);
void sleep_in_ms(int sleep_ms);
void thread_finish(t_phil **phil_arr);
void *monitor(void *ptr);
void thread_create(t_phil **phil_arr);
void *philo(void *ptr);
t_status *parsing(int argc, char **argv);
int ft_atoi(const char *str);
void *ft_calloc(size_t count, size_t size);
int ft_strncmp(const char *s1, const char *s2, size_t n);
size_t ft_strlen(const char *s);
size_t get_time_in_ms(void);
int print_dead(t_phil *p);
#endif