diff --git a/src/main/java/de/tudbut/tools/Lock.java b/src/main/java/de/tudbut/tools/Lock.java index 968b563..71804c7 100644 --- a/src/main/java/de/tudbut/tools/Lock.java +++ b/src/main/java/de/tudbut/tools/Lock.java @@ -56,16 +56,14 @@ public class Lock extends SimpleLock { * Wait until unlocked, either by a timer or manually */ public synchronized void waitHere() { - if(!isTimed) { - do - super.waitHere(); - while(relocking); - return; - } - if(!super.isLocked()) return; + do { + if(!isTimed) { + super.waitHere(); + continue; + } long wt = timeLeft0(); if(wt == 0) { unlock(); @@ -82,30 +80,29 @@ public class Lock extends SimpleLock { public synchronized void waitHere(int timeout) { if(timeout == 0) return; - long start = System.currentTimeMillis(); - if(!isTimed) { - do { - long sectionOffset = System.currentTimeMillis() - start; - long wt = timeout - sectionOffset; - if(wt == 0) - break; - super.waitHere(wt); - } while(relocking); - return; - } - if(!super.isLocked()) return; + + long start = System.currentTimeMillis(); do { + long sectionOffset = System.currentTimeMillis() - start; + + if(!isTimed) { + long wt = timeout - sectionOffset; + if(wt <= 0) + return; + super.waitHere(wt); + continue; + } + long wt = timeLeft0(); if(wt == 0) { unlock(); return; } - long sectionOffset = System.currentTimeMillis() - start; wt = Math.min(wt, timeout - sectionOffset); - if(wt == 0) - break; + if(wt <= 0) + return; super.waitHere(wt); } while(relocking); }