projects
/
IRC.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
2f0f05dde4d3fcb4f7dabd5fac8b0baa2ad1bc1c
[IRC.git]
/
Robust
/
src
/
Benchmarks
/
Prefetch
/
Em3d
/
dsm
/
Barrier.java
1
public class Barrier {
2
int numthreads;
3
int entercount;
4
boolean cleared;
5
6
public Barrier(int n) {
7
numthreads=n;
8
cleared = false;
9
entercount = 0;
10
}
11
12
public Barrier() {
13
}
14
15
public void reset() {
16
cleared = false;
17
entercount = 0;
18
}
19
20
public static void enterBarrier(Barrier b) {
21
int tmp;
22
boolean retry=true;
23
24
if(b.numthreads == 1)
25
return;
26
27
do {
28
atomic {
29
if (!b.cleared) {
30
b.entercount++;
31
tmp = b.entercount;
32
if (tmp==b.numthreads) {
33
b.cleared=true;
34
b.entercount--;
35
return;
36
}
37
retry=false;
38
}
39
}
40
} while(retry);
41
42
while(true) {
43
atomic {
44
if (b.cleared) {
45
b.entercount--;
46
int count = b.entercount;
47
if (count==0)
48
b.cleared=false;
49
return;
50
}
51
}
52
}
53
}
54
}