Skip to content
Commits on Source (2)
  • Raymond Toy's avatar
    Minor cosmetic tweaks · 05585b8d
    Raymond Toy authored
    o Include math.h before netdb.h (from Carl)
    o Use ceil instead of trunc and add comment on why.
    o Conform to cmucl style.
    05585b8d
  • Raymond Toy's avatar
    Add test for issue 26 · 9e99edb8
    Raymond Toy authored
    Basically used the repro case from the issue.
    9e99edb8
......@@ -6,11 +6,11 @@
*/
#include <errno.h>
#include <math.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "os.h"
#include "internals.h"
......@@ -568,7 +568,8 @@ int ieee754_rem_pio2(double x, double *y0, double *y1)
/*
* sleep for the given number of seconds, even if we're interrupted.
*/
void os_sleep(double seconds)
void
os_sleep(double seconds)
{
struct timespec requested;
struct timespec remaining;
......@@ -577,7 +578,12 @@ void os_sleep(double seconds)
fractional = modf(seconds, &integral);
requested.tv_sec = (time_t) integral;
requested.tv_nsec = (long) trunc(fractional * 1e9);
/*
* Round up just in case; it's probably better to sleep slightly
* too long than to sleep for too short a time.
*/
requested.tv_nsec = (long) ceil(fractional * 1e9);
while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) {
requested = remaining;
}
......
......@@ -347,3 +347,14 @@
(assert (null (set-difference directories
'(".dir" "dir")
:test #'string-equal)))))
(define-test issue.26
(:tag :issues)
(let ((start-time (get-universal-time)))
(let ((p (ext:run-program "/usr/bin/env" '("sleep" "1") :wait nil)))
(declare (ignore p))
(sleep 5)
;; We expect to have slept for at least 5 sec, but since
;; get-universal-time only has an accuracy of 1 sec, just verify
;; more than 3 sec have elapsed.
(assert-true (>= (- (get-universal-time) start-time) 3)))))