don't do a looped cond.await(timeout, unit) as that handles spurious wakeups, and it'll be buggy if the wakeup is due to a call to clear()

This commit is contained in:
Shikhar Bhushan
2012-10-21 01:21:36 +05:30
parent 2fdafb76fd
commit 4c5da634ad

View File

@@ -162,11 +162,14 @@ public class Promise<V, T extends Throwable> {
if (val != null)
return val;
log.debug("Awaiting <<{}>>", name);
while (val == null && pendingEx == null)
if (timeout == 0)
if (timeout == 0) {
while (val == null && pendingEx == null) {
cond.await();
else if (!cond.await(timeout, unit))
}
} else {
if (!cond.await(timeout, unit))
return null;
}
if (pendingEx != null) {
log.error("<<{}>> woke to: {}", name, pendingEx.toString());
throw pendingEx;