blob: 2fb4f5cb8c83aa616bec872b0b97d885a5cda697 (
plain)
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
|
package org.reprap.comms.snap;
// A temporary class to allow locking of comms while waiting
// for the asynchronous context delivery mechanism to be implemented
public class CommsLock {
private boolean locked = false;
synchronized public void lock() {
while(locked) {
//System.out.println("Lock: " + Thread.currentThread().getName() + " waiting");
try {
wait();
} catch (InterruptedException e) {
// Ignore interrupts and continue
}
}
locked = true;
//System.out.println("Lock: " + Thread.currentThread().getName() + " acquired");
}
synchronized public void unlock() {
if (!locked)
System.out.println("Warning: Calling unlock from an already unlocked state!");
locked = false;
notify();
//System.out.println("Unlock: " + Thread.currentThread().getName() + " released");
}
}
|