-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathVectorClockEvent.java
More file actions
88 lines (72 loc) · 2.9 KB
/
Copy pathVectorClockEvent.java
File metadata and controls
88 lines (72 loc) · 2.9 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package engine.pattern.PatternTrack;
import engine.pattern.PatternEvent;
import util.vectorclock.VectorClock;
public class VectorClockEvent extends PatternEvent<VectorClockState> {
@Override
public boolean Handle(VectorClockState state) {
super.Handle(state);
return state.extendWitness(this.locId, this.thread, this.getTimeStamp(state));
}
private void incrementCurrentThreadClock(VectorClockState state, VectorClock vc) {
int threadId = state.getThreadIndex(thread);
vc.setClockIndex(threadId, vc.getClockIndex(threadId) + 1);
}
public boolean HandleSubAcquire(VectorClockState state) {
VectorClock L_l = state.getLockClock(lock);
VectorClock C_t = state.getThreadClock(thread);
C_t.updateWithMax(C_t, L_l);
incrementCurrentThreadClock(state, C_t);
return false;
}
public boolean HandleSubRelease(VectorClockState state) {
VectorClock L_l = state.getLockClock(lock);
VectorClock C_t = state.getThreadClock(thread);
incrementCurrentThreadClock(state, C_t);
L_l.copyFrom(C_t);
return false;
}
public boolean HandleSubRead(VectorClockState state) {
VectorClock C_t = state.getThreadClock(thread);
VectorClock W_x = state.getWriteClock(variable);
VectorClock R_x = state.getReadClock(variable);
C_t.updateWithMax(C_t, W_x);
incrementCurrentThreadClock(state, C_t);
R_x.updateWithMax(R_x, C_t);
return false;
}
public boolean HandleSubWrite(VectorClockState state) {
VectorClock C_t = state.getThreadClock(thread);
VectorClock W_x = state.getWriteClock(variable);
VectorClock R_x = state.getReadClock(variable);
C_t.updateWithMax(C_t, W_x, R_x);
incrementCurrentThreadClock(state, C_t);
W_x.copyFrom(C_t);
return false;
}
public boolean HandleSubFork(VectorClockState state) {
VectorClock C_t = state.getThreadClock(thread);
VectorClock C_u = state.getThreadClock(target);
incrementCurrentThreadClock(state, C_t);
C_u.copyFrom(C_t);
C_u.setClockIndex(state.getThreadIndex(target), 1);
return false;
}
public boolean HandleSubJoin(VectorClockState state) {
VectorClock C_t = state.getThreadClock(thread);
VectorClock C_u = state.getThreadClock(target);
C_t.updateWithMax(C_t, C_u);
incrementCurrentThreadClock(state, C_t);
return false;
}
public boolean HandleSubBegin(VectorClockState state) {
incrementCurrentThreadClock(state, state.getThreadClock(thread));
return false;
}
public boolean HandleSubEnd(VectorClockState state) {
incrementCurrentThreadClock(state, state.getThreadClock(thread));
return false;
}
private VectorClock getTimeStamp(VectorClockState state) {
return new VectorClock(state.getThreadClock(thread));
}
}