-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitor.java
69 lines (58 loc) · 1.43 KB
/
Monitor.java
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
64
65
66
67
68
69
import java.util.concurrent.locks.ReentrantLock;
import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
public class Monitor implements Register{
private Lock laas = new ReentrantLock();
Condition notEmpty = laas.newCondition();
private SubsekvensRegister register;
CountDownLatch latch;
volatile boolean ferdig;
Monitor(int antall){
register = new SubsekvensRegister();
ferdig = false;
latch = new CountDownLatch(antall);
}
Monitor(){
register = new SubsekvensRegister();
}
@Override
public void settInn(HashMap<String, Subsekvens> h) {
try {
laas.lock();
register.settInn(h);
notEmpty.signalAll();
} finally{
laas.unlock();
}
}
@Override
public HashMap<String, Subsekvens> taUt() {
laas.lock();
try {
return register.taUt();
} finally {
laas.unlock();
}
}
int size(){
try{
laas.lock();
return register.hashBeholder.size();
}finally{
laas.unlock();
}
}
void settFerdig(){
try{
laas.lock();
ferdig = true;
}finally{
laas.unlock();
}
}
boolean erFerdig(){
return ferdig;
}
}