-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.h
50 lines (40 loc) · 1.11 KB
/
simulation.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
/**
* \brief Simulation data structure
*
* \author Miguel Oliveira e Silva - 2016
*/
#ifndef SIMULATION_H
#define SIMULATION_H
#include "pthread.h"
struct _Waiter_;
struct _Parameters_;
struct _DiningRoom_;
struct _Philosopher_;
typedef struct _Simulation_ {
struct _Parameters_* params;
struct _DiningRoom_* diningRoom;
struct _Philosopher_** philosophers;
struct _Waiter_* waiter;
} Simulation;
typedef struct {
pthread_t t_waiter;
pthread_t *t_philo;
} Threads;
typedef struct {
unsigned int phi_id; /* id. do thread filósofo */
unsigned int lifetime;
Simulation* sim; /* número de iterações */
} THREAD_PAR;
#include "parameters.h"
#include "dining-room.h"
#include "philosopher.h"
#include "waiter.h"
/** \brief locking flag which warrants mutual exclusion inside the monitor */
extern pthread_mutex_t accessCR;
extern pthread_cond_t wantCutlery;
extern pthread_cond_t wantPizza;
extern pthread_cond_t wantSpaghetti;
extern pthread_cond_t waiterNeeded;
Simulation* initSimulation(Simulation* sim, Parameters* params);
void* mem_alloc(int size);
#endif