guile-commits
[Top][All Lists]
Advanced

[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!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]