[Git][cmucl/cmucl][rtoy-issue-26] 2 commits: Minor cosmetic tweaks

Raymond Toy rtoy at common-lisp.net
Tue Nov 29 05:14:43 UTC 2016


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/e5777ecb2f2581f6788f7136adc78f129215d481...9e99edb82f2add0d91a9bec5cdb798e48fa794e5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20161129/3b4123c6/attachment-0001.html>


More information about the cmucl-cvs mailing list