-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFCFS_WH24.h
53 lines (48 loc) · 1.48 KB
/
FCFS_WH24.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
// Macros to bracket a non-FCFS lock acquire to make it FCFS, e.g.:
// FCFSintro(); acquire(m); FCFSexit();
#include "FCFSTest.h"
#define odd( v ) (v & 1)
#ifdef FCFS
#define FCFSGlobal() \
FCFSTestGlobal(); \
static VTYPE * FCFSturn CALIGN;
#define FCFSLocal() TYPE FCFSnx CALIGN, FCFScopy[N] CALIGN
#define FCFSEnter() \
FCFSTestIntroTop(); \
FCFSnx = FCFSturn[id] + 1; \
FCFSturn[id] = -1; \
Fence(); \
for ( typeof(N) k = 0; k < N; k += 1 ) FCFScopy[k] = FCFSturn[k]; \
FCFSturn[id] = FCFSnx; \
FCFSTestIntroMid(); \
for ( typeof(N) k = 0; k < N; k += 1 ) \
if ( odd( FCFScopy[k] ) ) \
await( FCFSturn[k] != FCFScopy[k] )
#define FCFSExitAcq() \
FCFSTestIntroBot(); \
/* FCFSturn[id] = ((FCFSturn[id] + 1) % 6); */ \
/* FCFSturn[id] = (7 & (FCFSturn[id] + 1)); */ \
TYPE FCFStemp = FCFSturn[id]; \
FCFSturn[id] = (FCFStemp == 5 ? 0 : FCFStemp + 1 )
#define FCFSExitRel()
#define FCFSCtor() \
FCFSturn = Allocator( sizeof(typeof(FCFSturn[0])) * N ); \
for ( typeof(N) i = 0; i < N; i += 1 ) { \
FCFSturn[i] = 0; \
} \
FCFSTestCtor()
#define FCFSDtor() \
FCFSTestDtor(); \
free( (void *)FCFSturn )
#else
#define FCFSGlobal() int __attribute__(( unused )) FCFSGlobal
#define FCFSLocal() int __attribute__(( unused )) FCFSLocal
#define FCFSEnter() do {} while(0)
#define FCFSExitAcq() do {} while(0)
#define FCFSExitRel() do {} while(0)
#define FCFSCtor() do {} while(0)
#define FCFSDtor() do {} while(0)
#endif // FCFS
// Local Variables: //
// tab-width: 4 //
// End: //