[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.
- [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, 2016/10/31
- [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 <=
- [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
- [Guile-commits] 03/17: srfi-18: Improve style., Andy Wingo, 2016/10/31
- [Guile-commits] 15/17: srfi-18: thread-terminate! without cleanup handlers, Andy Wingo, 2016/10/31
- [Guile-commits] 01/17: cancel-thread via asyncs, not pthread_cancel, Andy Wingo, 2016/10/31
- [Guile-commits] 08/17: srfi-18: Use srfi-35 conditions., Andy Wingo, 2016/10/31
- [Guile-commits] 16/17: REPL server avoids thread cleanup handlers, Andy Wingo, 2016/10/31
- [Guile-commits] 09/17: srfi-18: Inline uses of srfi-18-exception-preserver., Andy Wingo, 2016/10/31