Prevented synchronization issue with UnitSemaphoreAccessLock

Using the boolean outside of the synchronized block might have caused issues.
This commit is contained in:
Risto Lahtela 2021-02-12 09:27:56 +02:00
parent 2c9c691b4f
commit 5c01cde102

View File

@ -35,20 +35,20 @@ public class UnitSemaphoreAccessLock {
public void enter() {
try {
if (accessing.get()) {
synchronized (lockObject) {
synchronized (lockObject) {
if (accessing.get()) {
lockObject.wait();
}
accessing.set(true);
}
accessing.set(true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public void exit() {
accessing.set(false);
synchronized (lockObject) {
accessing.set(false);
lockObject.notify();
}
}