-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBarrierTreeA.c
59 lines (52 loc) · 1.56 KB
/
BarrierTreeA.c
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
typedef VTYPE CALIGN * Barrier;
static TYPE PAD1 CALIGN __attribute__(( unused )); // protect further false sharing
static Barrier b CALIGN;
static TYPE PAD2 CALIGN __attribute__(( unused )); // protect further false sharing
#define BARRIER_DECL
#define BARRIER_CALL block( b, p );
static inline void block( Barrier aa, TYPE p ) {
TYPE aap = aa[p]; // optimization
if ( p == 0 ) {
#if 0
TYPE sp, stack[N]; // Lamport attempt to reduce busy wait
for ( sp = 1; sp < N; sp += 1 ) stack[sp] = sp;
while ( sp > 1 ) { // skip p[0]
for ( TYPE i = 1; i < sp; ) {
if ( aap != aa[stack[i]] ) {
sp -= 1;
stack[i] = stack[sp];
} else {
i += 1;
} // if
} // for
} // while
#else
for ( TYPE kk = 1; kk < N ; kk += 1 ) { // skip p[0]
await( aap != aa[kk] );
} // for
#endif // 0
// CALL ACTION CALLBACK BEFORE TRIGGERING BARRIER
aa[0] = ! aap; // release waiting threads
Fence();
} else {
aap = ! aap;
aa[p] = aap;
Fence();
await( aap == aa[0] ); // wait for p0 to see all waiting threads
} // if
} // block
#include "BarrierWorker.c"
void __attribute__((noinline)) ctor() {
worker_ctor();
b = Allocator( sizeof(typeof(b[0])) * N );
for ( size_t i = 0; i < N; i += 1 ) {
b[i] = false;
} // for
} // ctor
void __attribute__((noinline)) dtor() {
free( (void *)b );
worker_dtor();
} // dtor
// Local Variables: //
// compile-command: "gcc -Wall -Wextra -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=BarrierTreeA Harness.c -lpthread -lm -D`hostname` -DCFMT" //
// End: //