Raymond Toy pushed to branch rtoy-issue-26 at cmucl / cmucl
Commits:
-
05585b8d
by Raymond Toy at 2016-11-28T21:05:02-08:00
-
9e99edb8
by Raymond Toy at 2016-11-28T21:14:27-08:00
2 changed files:
Changes:
... | ... | @@ -6,11 +6,11 @@ |
6 | 6 |
*/
|
7 | 7 |
|
8 | 8 |
#include <errno.h>
|
9 |
#include <math.h>
|
|
9 | 10 |
#include <netdb.h>
|
10 | 11 |
#include <stdio.h>
|
11 | 12 |
#include <string.h>
|
12 | 13 |
#include <time.h>
|
13 |
#include <math.h>
|
|
14 | 14 |
|
15 | 15 |
#include "os.h"
|
16 | 16 |
#include "internals.h"
|
... | ... | @@ -568,7 +568,8 @@ int ieee754_rem_pio2(double x, double *y0, double *y1) |
568 | 568 |
/*
|
569 | 569 |
* sleep for the given number of seconds, even if we're interrupted.
|
570 | 570 |
*/
|
571 |
void os_sleep(double seconds)
|
|
571 |
void
|
|
572 |
os_sleep(double seconds)
|
|
572 | 573 |
{
|
573 | 574 |
struct timespec requested;
|
574 | 575 |
struct timespec remaining;
|
... | ... | @@ -577,7 +578,12 @@ void os_sleep(double seconds) |
577 | 578 |
|
578 | 579 |
fractional = modf(seconds, &integral);
|
579 | 580 |
requested.tv_sec = (time_t) integral;
|
580 |
requested.tv_nsec = (long) trunc(fractional * 1e9);
|
|
581 |
/*
|
|
582 |
* Round up just in case; it's probably better to sleep slightly
|
|
583 |
* too long than to sleep for too short a time.
|
|
584 |
*/
|
|
585 |
requested.tv_nsec = (long) ceil(fractional * 1e9);
|
|
586 |
|
|
581 | 587 |
while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) {
|
582 | 588 |
requested = remaining;
|
583 | 589 |
}
|
... | ... | @@ -347,3 +347,14 @@ |
347 | 347 |
(assert (null (set-difference directories
|
348 | 348 |
'(".dir" "dir")
|
349 | 349 |
:test #'string-equal)))))
|
350 |
|
|
351 |
(define-test issue.26
|
|
352 |
(:tag :issues)
|
|
353 |
(let ((start-time (get-universal-time)))
|
|
354 |
(let ((p (ext:run-program "/usr/bin/env" '("sleep" "1") :wait nil)))
|
|
355 |
(declare (ignore p))
|
|
356 |
(sleep 5)
|
|
357 |
;; We expect to have slept for at least 5 sec, but since
|
|
358 |
;; get-universal-time only has an accuracy of 1 sec, just verify
|
|
359 |
;; more than 3 sec have elapsed.
|
|
360 |
(assert-true (>= (- (get-universal-time) start-time) 3)))))
|