-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphilo.h
59 lines (52 loc) · 1.94 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ytaya <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/06 17:12:51 by ytaya #+# #+# */
/* Updated: 2022/02/07 23:46:04 by ytaya ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# include <stdio.h>
# include <stdlib.h>
# include <pthread.h>
# include <sys/time.h>
# include <unistd.h>
typedef struct s_program_args
{
int n_philo;
int t_die;
int t_eat;
int t_sleep;
int n_meals;
long t_initphilo;
pthread_mutex_t write;
int stop;
}t_program_args;
typedef struct s_philosopher
{
long t_lastmeal;
pthread_t thread_id;
int id;
int n_meals;
int iseating;
pthread_mutex_t fork;
t_program_args *args;
struct s_philosopher *next;
}t_philosopher;
t_philosopher *ft_lstnew(int id, t_program_args *args);
t_philosopher *ft_lstlast(t_philosopher *head);
void ft_args_init(t_program_args *args, char **argv);
void ft_routine_manager(t_philosopher *philos);
void ft_sleep_ms(int time);
void ft_write(t_philosopher *philo, char *msg, long long time);
long ft_time_now(void);
void *ft_routine(void *arg);
void ft_create_threads(t_philosopher *philos);
t_philosopher *ft_philos_init(t_program_args *args);
void ft_lstadd_back(t_philosopher **lst, t_philosopher *new);
#endif