Raymond Toy pushed to branch rtoy-issue-26 at cmucl / cmucl
Commits: 05585b8d by Raymond Toy at 2016-11-28T21:05:02-08:00 Minor cosmetic tweaks
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.
- - - - - 9e99edb8 by Raymond Toy at 2016-11-28T21:14:27-08:00 Add test for issue 26
Basically used the repro case from the issue.
- - - - -
2 changed files:
- src/lisp/os-common.c - tests/issues.lisp
Changes:
===================================== src/lisp/os-common.c ===================================== --- a/src/lisp/os-common.c +++ b/src/lisp/os-common.c @@ -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; }
===================================== tests/issues.lisp ===================================== --- a/tests/issues.lisp +++ b/tests/issues.lisp @@ -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)))))
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/compare/e5777ecb2f2581f6788f7136a...