guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 12/17: Refactor thread-join! to use optional args.


From: Andy Wingo
Subject: [Guile-commits] 12/17: Refactor thread-join! to use optional args.
Date: Mon, 31 Oct 2016 21:39:37 +0000 (UTC)

wingo pushed a commit to branch master
in repository guile.

commit 59fdf9cdcd1dfbe0e9542ea82678eee4fb62d753
Author: Andy Wingo <address@hidden>
Date:   Mon Oct 31 21:36:56 2016 +0100

    Refactor thread-join! to use optional args.
    
    * module/srfi/srfi-18.scm (thread-join!): Use optional args.  Also don't
      treat false return values from threads as meaning anything.
---
 module/srfi/srfi-18.scm |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm
index 6ff88ab..aa2b2b2 100644
--- a/module/srfi/srfi-18.scm
+++ b/module/srfi/srfi-18.scm
@@ -254,15 +254,22 @@
     (threads:cancel-thread thread)
     *unspecified*))
 
-(define (thread-join! thread . args) 
+;; A unique value.
+(define %sentinel (list 1))
+(define* (thread-join! thread #:optional (timeout %sentinel)
+                       (timeoutval %sentinel))
   (with-exception-handlers-here
    (lambda ()
-     (let ((v (apply threads:join-thread thread args))
-           (e (thread->exception thread)))
-       (if (and (= (length args) 1) (not v))
-           (srfi-34:raise (condition (&join-timeout-exception))))
-       (if e (srfi-34:raise e))
-       v))))
+     (let ((v (if (eq? timeout %sentinel)
+                  (threads:join-thread thread)
+                  (threads:join-thread thread timeout %sentinel))))
+       (cond
+        ((eq? v %sentinel)
+         (if (eq? timeoutval %sentinel)
+             (srfi-34:raise (condition (&join-timeout-exception)))
+             timeoutval))
+        ((thread->exception thread) => srfi-34:raise)
+        (else v))))))
 
 ;; MUTEXES
 ;; These functions are all pass-thrus to the existing Guile implementations.



reply via email to

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