Skip to content
Snippets Groups Projects
Commit e5777ecb authored by Raymond Toy's avatar Raymond Toy
Browse files

Fix #26: Use nanosleep to sleep

lisp/os-common.c:
o Implement os_sleep(double) to sleep for the given number of
  seconds.  Uses nanosleep on all platforms to sleep, taking care to
  sleep more if nanosleep was interrupted.

code/lispinit.lisp:
code/multi-proc.lisp:
o Use the new os_sleep function to sleep for the requested amount of
  time.
parent 63264651
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)))))
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment