[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 05/17: srfi-18: Simplify thread-sleep!, thread-terminate
From: |
Andy Wingo |
Subject: |
[Guile-commits] 05/17: srfi-18: Simplify thread-sleep!, thread-terminate!. |
Date: |
Mon, 31 Oct 2016 21:39:37 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit bbcc12815328e24686dfd283af0fdb9c80db67f4
Author: Andy Wingo <address@hidden>
Date: Sun Oct 30 21:43:51 2016 +0100
srfi-18: Simplify thread-sleep!, thread-terminate!.
* module/srfi/srfi-18.scm (thread-sleep!): Use `when'.
(thread-terminate!): Simplify.
---
module/srfi/srfi-18.scm | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm
index adad0d9..b3a0643 100644
--- a/module/srfi/srfi-18.scm
+++ b/module/srfi/srfi-18.scm
@@ -233,8 +233,8 @@
'()))))
(secs (inexact->exact (truncate t)))
(usecs (inexact->exact (truncate (* (- t secs) 1000000)))))
- (and (> secs 0) (sleep secs))
- (and (> usecs 0) (usleep usecs))
+ (when (> secs 0) (sleep secs))
+ (when (> usecs 0) (usleep usecs))
*unspecified*))
;; A convenience function for installing exception handlers on SRFI-18
@@ -254,23 +254,19 @@
;; terminated-thread exception, as per SRFI-18,
(define (thread-terminate! thread)
- (define (thread-terminate-inner!)
- (let ((current-handler (threads:thread-cleanup thread)))
- (if (thunk? current-handler)
- (threads:set-thread-cleanup!
- thread
- (lambda ()
- (with-exception-handler initial-handler
- current-handler)
- (srfi-18-exception-preserver
- terminated-thread-exception)))
- (threads:set-thread-cleanup!
- thread
- (lambda () (srfi-18-exception-preserver
- terminated-thread-exception))))
- (threads:cancel-thread thread)
- *unspecified*))
- (thread-terminate-inner!))
+ (let ((current-handler (threads:thread-cleanup thread)))
+ (threads:set-thread-cleanup!
+ thread
+ (if (thunk? current-handler)
+ (lambda ()
+ (with-exception-handler initial-handler
+ current-handler)
+ (srfi-18-exception-preserver
+ terminated-thread-exception))
+ (lambda () (srfi-18-exception-preserver
+ terminated-thread-exception))))
+ (threads:cancel-thread thread)
+ *unspecified*))
(define (thread-join! thread . args)
(define thread-join-inner!
- [Guile-commits] branch master updated (c957ec7 -> eeeee32), Andy Wingo, 2016/10/31
- [Guile-commits] 05/17: srfi-18: Simplify thread-sleep!, thread-terminate!.,
Andy Wingo <=
- [Guile-commits] 04/17: srfi-18: Use `match' in thread-start!., Andy Wingo, 2016/10/31
- [Guile-commits] 06/17: srfi-18: Use lambda* optional arguments., Andy Wingo, 2016/10/31
- [Guile-commits] 07/17: srfi-18: Use parameters., Andy Wingo, 2016/10/31
- [Guile-commits] 10/17: srfi-18: Avoid call/cc., Andy Wingo, 2016/10/31
- [Guile-commits] 11/17: Rationalize exception handling in srfi-18, Andy Wingo, 2016/10/31
- [Guile-commits] 17/17: Remove thread cleanup facility, Andy Wingo, 2016/10/31
- [Guile-commits] 02/17: Fix srfi-34 indentation, Andy Wingo, 2016/10/31
- [Guile-commits] 12/17: Refactor thread-join! to use optional args., Andy Wingo, 2016/10/31
- [Guile-commits] 13/17: Trim srfi-18 thread startup machinery, Andy Wingo, 2016/10/31
- [Guile-commits] 14/17: cancel-thread can take arguments, Andy Wingo, 2016/10/31