[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 07/17: srfi-18: Use parameters.
From: |
Andy Wingo |
Subject: |
[Guile-commits] 07/17: srfi-18: Use parameters. |
Date: |
Mon, 31 Oct 2016 21:39:37 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 0d57476f0a6ed30c420210946947740d3cf19fde
Author: Andy Wingo <address@hidden>
Date: Sun Oct 30 22:15:17 2016 +0100
srfi-18: Use parameters.
* module/srfi/srfi-18.scm: Use srfi-34 internally with srfi-34: prefix.
(current-exception-handler): Be a parameter.
(with-exception-handler): Adapt to current-exception-handler change.
(thread-join!, mutex-lock!): Adapt to use srfi-34: prefix.
---
module/srfi/srfi-18.scm | 40 +++++++++++++++-------------------------
1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm
index 6d74346..cb2ac1c 100644
--- a/module/srfi/srfi-18.scm
+++ b/module/srfi/srfi-18.scm
@@ -33,7 +33,7 @@
(define-module (srfi srfi-18)
#:use-module ((ice-9 threads) #:prefix threads:)
#:use-module (ice-9 match)
- #:use-module (srfi srfi-34)
+ #:use-module ((srfi srfi-34) #:prefix srfi-34:)
#:export (;; Threads
make-thread
thread-name
@@ -80,7 +80,7 @@
(threads:current-thread . current-thread)
(threads:thread? . thread?)
(threads:mutex? . mutex?)
- raise)
+ (srfi-34:raise . raise))
#:replace (current-time
make-thread
make-mutex
@@ -130,29 +130,19 @@
(cons uncaught-exception key)
(cons* uncaught-exception key args)))))
-(define (current-handler-stack)
- (let ((ct (threads:current-thread)))
- (or (hashq-ref thread-exception-handlers ct)
- (hashq-set! thread-exception-handlers ct (list initial-handler)))))
+(define current-exception-handler (make-parameter initial-handler))
(define (with-exception-handler handler thunk)
- (let ((ct (threads:current-thread))
- (hl (current-handler-stack)))
- (check-arg-type procedure? handler "with-exception-handler")
- (check-arg-type thunk? thunk "with-exception-handler")
- (hashq-set! thread-exception-handlers ct (cons handler hl))
- ((@ (srfi srfi-34) with-exception-handler)
+ (check-arg-type procedure? handler "with-exception-handler")
+ (check-arg-type thunk? thunk "with-exception-handler")
+ (srfi-34:with-exception-handler
+ (let ((prev-handler (current-exception-handler)))
(lambda (obj)
- (hashq-set! thread-exception-handlers ct hl)
- (handler obj))
- (lambda ()
- (call-with-values thunk
- (lambda res
- (hashq-set! thread-exception-handlers ct hl)
- (apply values res)))))))
-
-(define (current-exception-handler)
- (car (current-handler-stack)))
+ (parameterize ((current-exception-handler prev-handler))
+ (handler obj))))
+ (lambda ()
+ (parameterize ((current-exception-handler handler))
+ (thunk)))))
(define (join-timeout-exception? obj) (eq? obj join-timeout-exception))
(define (abandoned-mutex-exception? obj) (eq? obj abandoned-mutex-exception))
@@ -274,8 +264,8 @@
(let ((v (apply threads:join-thread thread args))
(e (thread->exception thread)))
(if (and (= (length args) 1) (not v))
- (raise join-timeout-exception))
- (if e (raise e))
+ (srfi-34:raise join-timeout-exception))
+ (if e (srfi-34:raise e))
v))))
(call/cc thread-join-inner!))
@@ -313,7 +303,7 @@
(wrap (lambda ()
(catch 'abandoned-mutex-error
(lambda () (apply threads:lock-mutex mutex args))
- (lambda (key . args) (raise abandoned-mutex-exception))))))
+ (lambda (key . args) (srfi-34:raise
abandoned-mutex-exception))))))
(call/cc mutex-lock-inner!))
(define (mutex-unlock! mutex . args)
- [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 <=
- [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
- [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