diff options
author | Thomas Watson | 2013-07-09 16:03:00 +0000 |
---|---|---|
committer | Thomas Watson | 2013-07-09 16:03:00 +0000 |
commit | f684280fce5808bfba65aaf86a1c1695894fba39 (patch) | |
tree | 46e1cb362eab71ba4be034b9fe06189b85d9fc82 /bundles/org.eclipse.osgi | |
parent | 273899e0bcff65b7ee939e66c3bcb7127487d484 (diff) | |
download | rt.equinox.framework-f684280fce5808bfba65aaf86a1c1695894fba39.tar.gz rt.equinox.framework-f684280fce5808bfba65aaf86a1c1695894fba39.tar.xz rt.equinox.framework-f684280fce5808bfba65aaf86a1c1695894fba39.zip |
Improve logic of waitForStop.
There was a bug that would result in leaking
threads in the forStop map if timeLeft became
a negative value. This is possible if time
taken to lock the bundle state took nearly the
amount of the timeout value.
Diffstat (limited to 'bundles/org.eclipse.osgi')
-rw-r--r-- | bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java index c02f26857..68f76416f 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java @@ -70,7 +70,7 @@ public abstract class SystemModule extends Module { } public ContainerEvent waitForStop(long timeout) throws InterruptedException { - final boolean waitForEver = timeout == 0; + final boolean waitForever = timeout == 0; final long start = System.currentTimeMillis(); final Thread current = Thread.currentThread(); long timeLeft = timeout; @@ -82,7 +82,6 @@ public abstract class SystemModule extends Module { } else { stateLocked = stateChangeLock.tryLock(timeLeft, TimeUnit.MILLISECONDS); } - timeLeft = waitForEver ? 0 : start + timeout - System.currentTimeMillis(); if (stateLocked) { synchronized (forStop) { try { @@ -96,17 +95,13 @@ public abstract class SystemModule extends Module { } finally { stateChangeLock.unlock(); } - if (event == null) { - do { - forStop.wait(timeLeft); - event = forStop.remove(current); - if (!waitForEver) { - timeLeft = start + timeout - System.currentTimeMillis(); - if (timeLeft == 0) { - timeLeft = -1; - } - } - } while (event == null && timeLeft >= 0); + timeLeft = waitForever ? 0 : start + timeout - System.currentTimeMillis(); + while (event == null && (waitForever || timeLeft > 0)) { + forStop.wait(timeLeft); + event = forStop.remove(current); + if (!waitForever) { + timeLeft = start + timeout - System.currentTimeMillis(); + } } } } |