unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Nathaniel Alderson <alderson@gmail.com>
To: guile-devel@gnu.org
Subject: [PATCH] calculate usecs correctly in thread-sleep!
Date: Thu, 19 Sep 2013 18:01:03 -0700	[thread overview]
Message-ID: <1379638863.16313.7.camel@unknown7845C43D7A58.gateway.2wire.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 112 bytes --]

Hi,
Attached is a patch for srfi-18 thread-sleep! to work for timeoutes less
than an second in the future.
Nate

[-- Attachment #2: 0001-calculate-usecs-correctly-in-thread-sleep.patch --]
[-- Type: text/x-patch, Size: 1999 bytes --]

From 6ac6565c6add2dbbd18dc6ee30fd062ba4349fd9 Mon Sep 17 00:00:00 2001
From: Nathaniel Alderson <alderson@gmail.com>
Date: Thu, 19 Sep 2013 14:02:26 -0700
Subject: [PATCH] calculate usecs correctly in thread-sleep!

---
 module/srfi/srfi-18.scm       | 4 ++--
 test-suite/tests/srfi-18.test | 8 +++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm
index 684a125..c394aef 100644
--- a/module/srfi/srfi-18.scm
+++ b/module/srfi/srfi-18.scm
@@ -236,7 +236,7 @@
 				   (list timeout) 
 				   '()))))
 	 (secs (inexact->exact (truncate t)))
-	 (usecs (inexact->exact (truncate (* (- t secs) 1000)))))
+	 (usecs (inexact->exact (truncate (* (- t secs) 1000000)))))
     (and (> secs 0) (sleep secs))
     (and (> usecs 0) (usleep usecs))
     *unspecified*))
@@ -380,4 +380,4 @@
 	 (cons (inexact->exact fx)
 	       (inexact->exact (truncate (* (- x fx) 1000000)))))))
 
-;; srfi-18.scm ends here
\ No newline at end of file
+;; srfi-18.scm ends here
diff --git a/test-suite/tests/srfi-18.test b/test-suite/tests/srfi-18.test
index 47f8f7f..ab05513 100644
--- a/test-suite/tests/srfi-18.test
+++ b/test-suite/tests/srfi-18.test
@@ -96,6 +96,12 @@
       (let ((old-secs (car (current-time))))
         (unspecified? (thread-sleep! (+ (time->seconds (current-time)))))))
 
+    (pass-if "thread sleeps fractions of a second"
+      (let* ((current (time->seconds (current-time)))
+             (future (+ current 0.5)))
+        (thread-sleep! future)
+        (>= (time->seconds (current-time)) future)))
+
     (pass-if "thread does not sleep on past time"
       (let ((past-time (seconds->time (- (time->seconds (current-time)) 2))))
         (unspecified? (thread-sleep! past-time)))))
@@ -479,4 +485,4 @@
                 (eq? (uncaught-exception-reason obj) 'foo)
                 (set! success #t)))
          (lambda () (thread-join! t)))
-        success)))))
\ No newline at end of file
+        success)))))
-- 
1.8.1.4


             reply	other threads:[~2013-09-20  1:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20  1:01 Nathaniel Alderson [this message]
2014-03-23 21:00 ` [PATCH] calculate usecs correctly in thread-sleep! Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379638863.16313.7.camel@unknown7845C43D7A58.gateway.2wire.net \
    --to=alderson@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).