-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFCFS_WH15.h
63 lines (58 loc) · 1.75 KB
/
FCFS_WH15.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
// Wim H. Hesselink, Mutual exclusion by four shared bits with not more than quadratic complexity, Science of Computer
// Programming, 102 (2015), Fig. 2
#include "FCFSTest.h"
#ifdef FCFS
#define FCFSGlobal() \
FCFSTestGlobal(); \
enum { FCFS_R = 3 }; \
static VTYPE * FCFSdw CALIGN, * FCFSturn CALIGN
#define FCFSLocal() \
typeof(N) Range CALIGN = N * FCFS_R, FCFSnx CALIGN = 0; \
TYPE FCFScopy[2 * N * FCFS_R];
#define FCFSEnter() \
FCFSTestIntroTop(); \
FCFSdw[id] = true; \
Fence(); \
for ( typeof(Range) k = 0; k < Range; k += 1 ) FCFScopy[k] = FCFSturn[k]; \
FCFSturn[2 * id + FCFSnx] = true; \
FCFSdw[id] = false; \
Fence(); \
FCFSTestIntroMid(); \
for ( typeof(Range) kk = 0; kk < Range; kk += 1 ) \
if ( FCFScopy[kk] ) { \
await( ! FCFSturn[kk] ); \
}
#define FCFSExitAcq() \
FCFSTestIntroBot(); \
FCFSturn[2 * id + FCFSnx] = false; \
FCFSnx = ! FCFSnx; \
Fence(); \
for ( typeof(N) thr = 0; thr < N; thr += 1 ) \
await( ! FCFSdw[thr] )
#define FCFSExitRel()
#define FCFSCtor() \
FCFSdw = Allocator( sizeof(typeof(FCFSdw[0])) * N ); \
for ( typeof(N) i = 0; i < N; i += 1 ) { \
FCFSdw[i] = 0; \
} \
FCFSturn = Allocator( sizeof(typeof(FCFSturn[0])) * 2 * N * FCFS_R ); \
for ( typeof(N) i = 0; i < 2 * N * FCFS_R; i += 1 ) { \
FCFSturn[i] = 0; \
} \
FCFSTestCtor()
#define FCFSDtor() \
FCFSTestDtor(); \
free( (void *)FCFSturn ); \
free( (void *)FCFSdw )
#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: //