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() { public void enter() {
try { try {
if (accessing.get()) { synchronized (lockObject) {
synchronized (lockObject) { if (accessing.get()) {
lockObject.wait(); lockObject.wait();
} }
accessing.set(true);
} }
accessing.set(true);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
public void exit() { public void exit() {
accessing.set(false);
synchronized (lockObject) { synchronized (lockObject) {
accessing.set(false);
lockObject.notify(); lockObject.notify();
} }
} }