mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
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.
This commit is contained in:
parent
8e305ee045
commit
59fdf9cdcd
1 changed files with 14 additions and 7 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue