-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
62 lines (53 loc) · 1.39 KB
/
util.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
#ifndef UTILH
#define UTILH
#include "main.h"
/* Parameters */
#define RESNUM 2
#define GROUPSIZE 2
#define BREAKTIME 5
#define BREAKPROB 25
#define TIMEINSECTION 5
#define SEC_IN_STATE 1
/* Messages */
#define REQQUEUE 1
#define ACKQUEUE 2
#define GROUPFORMED 3
#define REQRES 4
#define ACKRES 5
#define START 6
#define END 7
/* Packet Type */
typedef struct {
int ts;
int src;
int inGroup[GROUPSIZE];
} packet_t;
#define NITEMS 3
/* States */
typedef enum {
WantGroup, WaitingForGroup, Leader, Member, WaitingForRes, InSection, Break
} state_t;
typedef struct {
int id;
int lamport;
} idLamportPair;
extern MPI_Datatype MPI_PAKIET_T;
extern state_t state;
extern pthread_mutex_t stateMut;
extern pthread_mutex_t lamportMut;
extern pthread_mutex_t groupQueueMut;
extern pthread_mutex_t waitingForQueueMut;
extern pthread_mutex_t waitingForGroupMut;
extern pthread_mutex_t resQueueMut;
extern pthread_mutex_t waitingForResMut;
extern pthread_mutex_t waitingForStartMut;
extern pthread_mutex_t waitingForRelease;
extern std::vector<idLamportPair> groupQueue;
extern std::vector<idLamportPair> resQueue;
extern int groupMembers[GROUPSIZE];
void init_packet();
void sendPacket(packet_t *pkt, int destination, int tag);
void sendPacketToAllNoInc(packet_t *pkt, int tag);
void sendPacketToAllWithMeNoInc(packet_t *pkt, int tag);
void changeState(state_t);
#endif