-
Notifications
You must be signed in to change notification settings - Fork 0
/
philo.h
74 lines (61 loc) · 1.34 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
** philo.h for philo in /home/voinne_c/rendu/PSU_2014_philo
**
** Made by Cédric Voinnet
** Login <[email protected]>
**
** Started on Tue Feb 24 08:38:46 2015 Cédric Voinnet
** Last update Sat Feb 28 12:12:48 2015 Cédric Voinnet
*/
#ifndef PHILO_H_
# define PHILO_H_
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
# define NB_PHILO 7
# define NB_RICE 5
extern int g_rice_nb;
extern pthread_mutex_t *g_table;
extern pthread_mutex_t g_mutex_rice;
extern pthread_mutex_t g_mut_turn;
extern pthread_cond_t g_cond_turn;
typedef enum e_state
{
HUNGRY,
SLEEPY
} t_state;
typedef enum e_aff_state
{
STANDBY,
THINK,
EAT
} t_aff_state;
typedef struct s_gui
{
SDL_Surface *screen;
SDL_Rect *pos;
SDL_Surface **philos;
} t_gui;
typedef struct s_philo
{
pthread_t philo_thread;
unsigned int philo_num;
unsigned int rice;
char left_rod;
char right_rod;
t_state state;
t_aff_state aff_state;
char job_done;
} t_philo;
int init_table();
void destroy_table();
void *philosopher(void *);
void drop_rods(t_philo *);
void take_rods(t_philo *);
void left_hand(t_philo *);
void right_hand(t_philo *);
SDL_Surface **init_philos(SDL_Rect *, SDL_Surface *);
SDL_Rect *init_pos();
int init_gui(t_gui *);
void change_status(t_gui *, t_philo **);
void exit_gui(t_gui *);
#endif /* !PHILO_H_ */