mirror of
https://github.com/corda/corda.git
synced 2025-01-19 19:26:27 +00:00
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:
parent
929315e1f2
commit
49d19456d0
@ -2747,17 +2747,27 @@ Avian_sun_misc_Unsafe_park
|
|||||||
bool absolute = arguments[1];
|
bool absolute = arguments[1];
|
||||||
int64_t time; memcpy(&time, arguments + 2, 8);
|
int64_t time; memcpy(&time, arguments + 2, 8);
|
||||||
|
|
||||||
|
int64_t then = t->m->system->now();
|
||||||
|
|
||||||
if (absolute) {
|
if (absolute) {
|
||||||
time -= t->m->system->now();
|
time -= then;
|
||||||
if (time <= 0) {
|
if (time <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
time /= 1000 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorAcquire(t, local::interruptLock(t, t->javaThread));
|
monitorAcquire(t, local::interruptLock(t, t->javaThread));
|
||||||
while (not (threadUnparked(t, t->javaThread)
|
while (time > 0
|
||||||
or monitorWait(t, local::interruptLock(t, t->javaThread), time)))
|
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;
|
threadUnparked(t, t->javaThread) = false;
|
||||||
monitorRelease(t, local::interruptLock(t, t->javaThread));
|
monitorRelease(t, local::interruptLock(t, t->javaThread));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user