From 898d97d440f3d19b27e1f815fd4d009f24a36433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 16 Feb 2018 15:17:37 +0100 Subject: [PATCH] srfi-18: 'thread-sleep!' timeout-as-a-number is relative. This is a followup to . * module/srfi/srfi-18.scm (thread-sleep!): When TIMEOUT is a number, keep it as-is. * test-suite/tests/srfi-18.test ("thread sleep with number"): Pass 0 as the timeout. ("thread sleeps fractions of a second"): Pass 0.5 as the timeout. --- module/srfi/srfi-18.scm | 6 +++--- test-suite/tests/srfi-18.test | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm index 6d6596ffb..7177e0690 100644 --- a/module/srfi/srfi-18.scm +++ b/module/srfi/srfi-18.scm @@ -235,9 +235,9 @@ object (absolute point in time), or #f." (define (thread-yield!) (threads:yield) *unspecified*) (define (thread-sleep! timeout) - (let* ((ct (time->seconds (current-time))) - (t (cond ((time? timeout) (- (time->seconds timeout) ct)) - ((number? timeout) (- timeout ct)) + (let* ((t (cond ((time? timeout) (- (time->seconds timeout) + (time->seconds (current-time)))) + ((number? timeout) timeout) (else (scm-error 'wrong-type-arg "thread-sleep!" "Wrong type argument: ~S" (list timeout) diff --git a/test-suite/tests/srfi-18.test b/test-suite/tests/srfi-18.test index fc36dab8a..e5473391a 100644 --- a/test-suite/tests/srfi-18.test +++ b/test-suite/tests/srfi-18.test @@ -94,13 +94,12 @@ (unspecified? (thread-sleep! future-time)))) (pass-if "thread sleep with number" - (let ((old-secs (car (current-time)))) - (unspecified? (thread-sleep! (+ (time->seconds (current-time))))))) + (unspecified? (thread-sleep! 0))) (pass-if "thread sleeps fractions of a second" (let* ((current (time->seconds (current-time))) (future (+ current 0.5))) - (thread-sleep! future) + (thread-sleep! 0.5) (>= (time->seconds (current-time)) future))) (pass-if "thread does not sleep on past time"