Commit 081e9e28 authored by mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

Non-zero timeouts CL:SLEEP and THREADS:OBJECT-WAIT below the timer Planck...

Non-zero timeouts CL:SLEEP and THREADS:OBJECT-WAIT below the timer Planck limit interpolated as a nanosecond.

Thanks for James Lawrence for the consul.

Addresses #14632.
parent 0d729f70
...@@ -1264,7 +1264,9 @@ public final class LispThread extends LispObject ...@@ -1264,7 +1264,9 @@ public final class LispThread extends LispObject
doc="Causes the invoking thread to sleep for an interveral expressed in SECONDS.\n" doc="Causes the invoking thread to sleep for an interveral expressed in SECONDS.\n"
+ "SECONDS may be specified as a fraction of a second, with intervals\n" + "SECONDS may be specified as a fraction of a second, with intervals\n"
+ "less than or equal to a nanosecond resulting in a yield of execution\n" + "less than or equal to a nanosecond resulting in a yield of execution\n"
+ "to other waiting threads rather than an actual sleep.") + "to other waiting threads rather than an actual sleep.\n"
+ "A zero value of SECONDS *may* result in the JVM sleeping indefinitely,\n"
+ "depending on the implementation.")
private static final Primitive SLEEP = new Primitive("sleep", PACKAGE_CL, true) private static final Primitive SLEEP = new Primitive("sleep", PACKAGE_CL, true)
{ {
@Override @Override
...@@ -1272,10 +1274,15 @@ public final class LispThread extends LispObject ...@@ -1272,10 +1274,15 @@ public final class LispThread extends LispObject
{ {
long millis = sleepMillisPart(arg); long millis = sleepMillisPart(arg);
int nanos = sleepNanosPart(arg); int nanos = sleepNanosPart(arg);
boolean zeroArgP = arg.ZEROP() != NIL;
try { try {
if (millis == 0 && nanos == 0) { if (millis == 0 && nanos == 0) {
Thread.yield(); if (zeroArgP) {
Thread.sleep(0, 0);
} else {
Thread.sleep(0, 1);
}
} else { } else {
Thread.sleep(millis, nanos); Thread.sleep(millis, nanos);
} }
...@@ -1440,6 +1447,7 @@ public final class LispThread extends LispObject ...@@ -1440,6 +1447,7 @@ public final class LispThread extends LispObject
doc="Causes the current thread to block until object-notify or object-notify-all is called on OBJECT.\n" doc="Causes the current thread to block until object-notify or object-notify-all is called on OBJECT.\n"
+ "Optionally unblock execution after TIMEOUT seconds. A TIMEOUT of zero\n" + "Optionally unblock execution after TIMEOUT seconds. A TIMEOUT of zero\n"
+ "means to wait indefinitely.\n" + "means to wait indefinitely.\n"
+ "A non-zero TIMEOUT of less than a nanosecond is interpolated as a nanosecond wait."
+ "\n" + "\n"
+ "See the documentation of java.lang.Object.wait() for further\n" + "See the documentation of java.lang.Object.wait() for further\n"
+ "information.\n" + "information.\n"
...@@ -1467,9 +1475,20 @@ public final class LispThread extends LispObject ...@@ -1467,9 +1475,20 @@ public final class LispThread extends LispObject
public LispObject execute(LispObject object, LispObject timeout) public LispObject execute(LispObject object, LispObject timeout)
{ {
long millis = sleepMillisPart(timeout);
int nanos = sleepNanosPart(timeout);
boolean zeroArgP = timeout.ZEROP() != NIL;
try { try {
object.lockableInstance().wait(sleepMillisPart(timeout), if (millis == 0 && nanos == 0) {
sleepNanosPart(timeout)); if (zeroArgP) {
object.lockableInstance().wait(0, 0);
} else {
object.lockableInstance().wait(0, 1);
}
} else {
object.lockableInstance().wait(millis, nanos);
}
} }
catch (InterruptedException e) { catch (InterruptedException e) {
currentThread().processThreadInterrupts(); currentThread().processThreadInterrupts();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment