fix infinite wait in Unsafe.park

There were a couple of problems with the Avian_sun_misc_Unsafe_park
implementation in classpath-openjdk.cpp.  First, the wait time should
be interpreted as milliseconds if absolute, but as nanoseconds
otherwise, whereas we were treating it as milliseconds in both cases.
Second, there was no mechanism to exit the while loop after the
specified time; the only way we could exit was via an unpark or
interrupt.
This commit is contained in:
Joel Dice 2012-01-14 20:21:42 -07:00
parent 929315e1f2
commit 49d19456d0

View File

@ -2747,17 +2747,27 @@ Avian_sun_misc_Unsafe_park
bool absolute = arguments[1];
int64_t time; memcpy(&time, arguments + 2, 8);
int64_t then = t->m->system->now();
if (absolute) {
time -= t->m->system->now();
time -= then;
if (time <= 0) {
return;
}
} else {
time /= 1000 * 1000;
}
monitorAcquire(t, local::interruptLock(t, t->javaThread));
while (not (threadUnparked(t, t->javaThread)
or monitorWait(t, local::interruptLock(t, t->javaThread), time)))
{ }
while (time > 0
and (not (threadUnparked(t, t->javaThread)
or monitorWait
(t, local::interruptLock(t, t->javaThread), time))))
{
int64_t now = t->m->system->now();
time -= now - then;
then = now;
}
threadUnparked(t, t->javaThread) = false;
monitorRelease(t, local::interruptLock(t, t->javaThread));
}