diff --git a/src/code/lispinit.lisp b/src/code/lispinit.lisp index be5307c4c260f2c1f0dfb62919f256ddfbdf81d1..5ed7b9661c5cd08236ae4b3f87f607aa5484a117 100644 --- a/src/code/lispinit.lisp +++ b/src/code/lispinit.lisp @@ -515,12 +515,9 @@ :format-arguments (list n) :datum n :expected-type '(real 0))) - (multiple-value-bind (sec usec) - (if (integerp n) - (values n 0) - (multiple-value-bind (sec frac) (truncate n) - (values sec (truncate frac 1e-6)))) - (unix:unix-select 0 0 0 0 sec usec)) + (alien:alien-funcall + (alien:extern-alien "os_sleep" (function c-call:void double-float)) + (float n 1d0)) nil) ;;;; SCRUB-CONTROL-STACK diff --git a/src/code/multi-proc.lisp b/src/code/multi-proc.lisp index c73f0b41afe11e71d4af65c7a10180e0eeafde0e..fb5bcc043998c66597f4fc8cda72647ec107a43e 100644 --- a/src/code/multi-proc.lisp +++ b/src/code/multi-proc.lisp @@ -1643,12 +1643,9 @@ ;; Can't call process-wait if the scheduling is inhibited. *inhibit-scheduling*) ;; The initial-process may block. - (multiple-value-bind (sec usec) - (if (integerp n) - (values n 0) - (multiple-value-bind (sec frac)(truncate n) - (values sec (truncate frac 1e-6)))) - (unix:unix-select 0 0 0 0 sec usec)) + (alien:alien-funcall + (alien:extern-alien "os_sleep" (function c-call:void double-float)) + (float n 1d0)) nil) (t (process-wait-with-timeout "Sleep" n (constantly nil))))) diff --git a/src/lisp/os-common.c b/src/lisp/os-common.c index 5c8462a6311887f716a04d5c0baa0bf8370982d1..a936716d12379a03aa09f096860c2da56316fffe 100755 --- a/src/lisp/os-common.c +++ b/src/lisp/os-common.c @@ -9,6 +9,8 @@ #include <netdb.h> #include <stdio.h> #include <string.h> +#include <time.h> +#include <math.h> #include "os.h" #include "internals.h" @@ -562,3 +564,21 @@ int ieee754_rem_pio2(double x, double *y0, double *y1) return n; } + +/* + * sleep for the given number of seconds, even if we're interrupted. + */ +void os_sleep(double seconds) +{ + struct timespec requested; + struct timespec remaining; + double integral; + double fractional; + + fractional = modf(seconds, &integral); + requested.tv_sec = (time_t) integral; + requested.tv_nsec = (long) trunc(fractional * 1e9); + while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) { + requested = remaining; + } +}