-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathBarrierFai2.c
More file actions
46 lines (36 loc) · 1.29 KB
/
BarrierFai2.c
File metadata and controls
46 lines (36 loc) · 1.29 KB
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
#include "BarrierCallback.h"
typedef struct {
TYPE CALIGN group;
VSTYPE CALIGN low;
VSTYPE CALIGN high;
CBDECL();
} 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 );
// The first thread stops after it has incremented high, and has not incremented barcnt. Then the second thread sees
// all threads are at the barrier but barcnt == 1.
static inline bool block( Barrier * b ) {
CBSTART(); // must be first
STYPE ticket = Fai( b->high, 1 );
if ( LIKELY( ticket - b->low != (STYPE)(b->group - 1) ) ) { // wait ?
await( ticket - b->low < 0 );
return false;
} // if
CBEND(); // must appear in safe location
b->low += b->group;
return true;
} // block
#include "BarrierWorker.c"
void __attribute__((noinline)) ctor() {
worker_ctor();
b = (Barrier){ .group = N, .low = 0, .high = 0 CBINIT() };
} // ctor
void __attribute__((noinline)) dtor() {
worker_dtor();
} // dtor
// Local Variables: //
// compile-command: "gcc -Wall -Wextra -std=gnu11 -O3 -DNDEBUG -fno-reorder-functions -DPIN -DAlgorithm=BarrierFai2 Harness.c -lpthread -lm -D`hostname` -DCFMT" //
// End: //