From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nathaniel Alderson Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] calculate usecs correctly in thread-sleep! Date: Thu, 19 Sep 2013 18:01:03 -0700 Message-ID: <1379638863.16313.7.camel@unknown7845C43D7A58.gateway.2wire.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-66M6ezZoSmR74vyzCXfR" X-Trace: ger.gmane.org 1379638889 1108 80.91.229.3 (20 Sep 2013 01:01:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 Sep 2013 01:01:29 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Sep 20 03:01:31 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VMp69-0004fS-U6 for guile-devel@m.gmane.org; Fri, 20 Sep 2013 03:01:30 +0200 Original-Received: from localhost ([::1]:53676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMp69-0004wZ-8b for guile-devel@m.gmane.org; Thu, 19 Sep 2013 21:01:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMp5x-0004uu-UG for guile-devel@gnu.org; Thu, 19 Sep 2013 21:01:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMp5o-0005Sn-D2 for guile-devel@gnu.org; Thu, 19 Sep 2013 21:01:17 -0400 Original-Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]:38293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMp5o-0005SB-6Y for guile-devel@gnu.org; Thu, 19 Sep 2013 21:01:08 -0400 Original-Received: by mail-pb0-f44.google.com with SMTP id xa7so9083932pbc.3 for ; Thu, 19 Sep 2013 18:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:date:content-type:mime-version; bh=l2jqA73gy+uG/x+P0aaZnEGedtHu+VzjydhTaYNCEow=; b=o56hpHO4KMSUX2gE/RvodhgZNu9GBUW820sFiH6t1jgZWpk0JAS35/C/7P9ozjYJAg wJP27DZc3hIDscF55n7IW5vKu6eVt3ivwMYXo/e0V6Shnmj10kHfR/EUoUOJ1hByA77o chx5ittKG61rc23jRBdR1PU2JglxNZvWJ6+5TMCguCfjyheyKnvRwBe0kYfCEgzXl92P RpQ/9VxVWedOg2Fc6wZ4j88idgjqKX6E+wCJOOd1OYWm0nf3c6iVYmDgWp9tk0ICtTAF 7RuHNhmo9aAhod+CNZM40mM2JDzaJB9c98zip021dUciStpVofo3whEvy6+8LUVT/+Hq fZ9Q== X-Received: by 10.68.6.232 with SMTP id e8mr4942264pba.132.1379638866864; Thu, 19 Sep 2013 18:01:06 -0700 (PDT) Original-Received: from [192.168.1.66] (75-23-174-70.lightspeed.sagsca.sbcglobal.net. [75.23.174.70]) by mx.google.com with ESMTPSA id xs1sm15135772pac.7.1969.12.31.16.00.00 (version=SSLv3 cipher=RC4-SHA bits=128/128); Thu, 19 Sep 2013 18:01:05 -0700 (PDT) X-Mailer: Evolution 3.6.4 (3.6.4-3.fc18) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22c X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16639 Archived-At: --=-66M6ezZoSmR74vyzCXfR Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hi, Attached is a patch for srfi-18 thread-sleep! to work for timeoutes less than an second in the future. Nate --=-66M6ezZoSmR74vyzCXfR Content-Disposition: attachment; filename="0001-calculate-usecs-correctly-in-thread-sleep.patch" Content-Type: text/x-patch; name="0001-calculate-usecs-correctly-in-thread-sleep.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 6ac6565c6add2dbbd18dc6ee30fd062ba4349fd9 Mon Sep 17 00:00:00 2001 From: Nathaniel Alderson 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 --=-66M6ezZoSmR74vyzCXfR--