[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 05/24: srfi-18 condition variables disjoint
From: |
Andy Wingo |
Subject: |
[Guile-commits] 05/24: srfi-18 condition variables disjoint |
Date: |
Sun, 6 Nov 2016 18:00:45 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 846f7e116e5ae0e9e25d3439fb24eac909a88629
Author: Andy Wingo <address@hidden>
Date: Fri Nov 4 20:29:44 2016 +0100
srfi-18 condition variables disjoint
* module/srfi/srfi-18.scm (<condition-variable>): New data type.
(make-thread): Use srfi-18 interfaces.
(mutex-unlock!): Adapt to optional cond argument being disjoint from
Guile condition variables.
(make-condition-variable, condition-variable-signal!)
(condition-variable-broadcast!): Adapt.
---
module/srfi/srfi-18.scm | 59 ++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 32 deletions(-)
diff --git a/module/srfi/srfi-18.scm b/module/srfi/srfi-18.scm
index bdfeef8..69c0338 100644
--- a/module/srfi/srfi-18.scm
+++ b/module/srfi/srfi-18.scm
@@ -80,15 +80,15 @@
terminated-thread-exception?
uncaught-exception?
uncaught-exception-reason)
- #:re-export ((threads:condition-variable? . condition-variable?)
- (threads:current-thread . current-thread)
+ #:re-export ((threads:current-thread . current-thread)
(threads:thread? . thread?)
(srfi-34:raise . raise))
#:replace (current-time
make-thread
make-mutex
mutex?
- make-condition-variable))
+ make-condition-variable
+ condition-variable?))
(unless (provided? 'threads)
(error "SRFI-18 requires Guile with threads support"))
@@ -118,6 +118,13 @@
(name mutex-name)
(specific mutex-specific mutex-specific-set!))
+(define-record-type <condition-variable>
+ (%make-condition-variable prim name specific)
+ condition-variable?
+ (prim condition-variable-prim)
+ (name condition-variable-name)
+ (specific condition-variable-specific condition-variable-specific-set!))
+
(define object-names (make-weak-key-hash-table))
(define object-specifics (make-weak-key-hash-table))
(define thread-start-conds (make-weak-key-hash-table))
@@ -180,7 +187,7 @@
(with-thread-mutex-cleanup
(lambda ()
(mutex-lock! sm)
- (threads:signal-condition-variable sc)
+ (condition-variable-signal! sc)
(mutex-unlock! sm sc)
(thunk))))
(lambda (key . args)
@@ -191,9 +198,8 @@
(('srfi-34 obj) obj)
(obj obj))))))))))))
(when name (hashq-set! object-names t name))
- (threads:wait-condition-variable sc (mutex-prim sm))
+ (mutex-unlock! sm sc)
(hashq-set! thread-start-conds t (cons sm sc))
- (mutex-unlock! sm)
t)))
(define (thread-name thread)
@@ -216,7 +222,7 @@
((smutex . scond)
(hashq-remove! thread-start-conds thread)
(mutex-lock! smutex)
- (threads:signal-condition-variable scond)
+ (condition-variable-signal! scond)
(mutex-unlock! smutex))
(#f #f))
thread)
@@ -315,41 +321,30 @@
(srfi-34:raise
(condition (&abandoned-mutex-exception))))))))
-(define (mutex-unlock! mutex . args)
- (apply threads:unlock-mutex (mutex-prim mutex) args))
+(define mutex-unlock!
+ (case-lambda
+ ((mutex)
+ (threads:unlock-mutex (mutex-prim mutex)))
+ ((mutex cond)
+ (threads:unlock-mutex (mutex-prim mutex)
+ (condition-variable-prim cond)))
+ ((mutex cond timeout)
+ (threads:unlock-mutex (mutex-prim mutex)
+ (condition-variable-prim cond)
+ timeout))))
;; CONDITION VARIABLES
;; These functions are all pass-thrus to the existing Guile implementations.
(define* (make-condition-variable #:optional name)
- (let ((m (threads:make-condition-variable)))
- (when name (hashq-set! object-names m name))
- m))
-
-(define (condition-variable-name condition-variable)
- (hashq-ref object-names (check-arg-type threads:condition-variable?
- condition-variable
- "condition-variable-name")))
-
-(define (condition-variable-specific condition-variable)
- (hashq-ref object-specifics (check-arg-type threads:condition-variable?
- condition-variable
- "condition-variable-specific")))
-
-(define (condition-variable-specific-set! condition-variable obj)
- (hashq-set! object-specifics
- (check-arg-type threads:condition-variable?
- condition-variable
- "condition-variable-specific-set!")
- obj)
- *unspecified*)
+ (%make-condition-variable (threads:make-condition-variable) name #f))
(define (condition-variable-signal! cond)
- (threads:signal-condition-variable cond)
+ (threads:signal-condition-variable (condition-variable-prim cond))
*unspecified*)
(define (condition-variable-broadcast! cond)
- (threads:broadcast-condition-variable cond)
+ (threads:broadcast-condition-variable (condition-variable-prim cond))
*unspecified*)
;; TIME
- [Guile-commits] branch master updated (fcc6a7b -> f8de980), Andy Wingo, 2016/11/06
- [Guile-commits] 04/24: Remove export srfi-18 never had, Andy Wingo, 2016/11/06
- [Guile-commits] 01/24: Fix typo in threads documentation, Andy Wingo, 2016/11/06
- [Guile-commits] 02/24: try-mutex in terms of mutex-lock, Andy Wingo, 2016/11/06
- [Guile-commits] 12/24: Remove fat mutex abandoned mutex error, Andy Wingo, 2016/11/06
- [Guile-commits] 09/24: SRFI-18 manages own mutex "abandoned" state, Andy Wingo, 2016/11/06
- [Guile-commits] 05/24: srfi-18 condition variables disjoint,
Andy Wingo <=
- [Guile-commits] 10/24: Remove thread-local weak mutex set, Andy Wingo, 2016/11/06
- [Guile-commits] 18/24: Back to simple unlock-mutex, Andy Wingo, 2016/11/06
- [Guile-commits] 08/24: Remove lock-mutex owner facility, Andy Wingo, 2016/11/06
- [Guile-commits] 14/24: SRFI-18 mutexes are not recursive, Andy Wingo, 2016/11/06
- [Guile-commits] 07/24: SRFI-18 threads disjoint from guile threads, Andy Wingo, 2016/11/06
- [Guile-commits] 21/24: scm_timed_lock_mutex replaces scm_lock_mutex_timed, Andy Wingo, 2016/11/06
- [Guile-commits] 15/24: Recursively locking a SRFI-18 mutex blocks, Andy Wingo, 2016/11/06
- [Guile-commits] 19/24: Separate fat mutex unlock and wait operations, Andy Wingo, 2016/11/06
- [Guile-commits] 06/24: Update SRFI-18 documentation., Andy Wingo, 2016/11/06
- [Guile-commits] 11/24: Remove thread held pthread_mutex field, Andy Wingo, 2016/11/06