unlock-thread-mutex
with-create-thread-continuation
with-thread-events-blocked
+ with-thread-mutex-lock
with-thread-mutex-locked
with-thread-mutex-unlocked
with-thread-timer-stopped
+ without-thread-mutex-lock
yield-current-thread)
(export (runtime interrupt-handler)
thread-timer-interrupt-handler)
(set-thread-mutex/owner! mutex thread)
(if thread (%signal-thread-event thread #f))
thread))
-\f
+
(define (try-lock-thread-mutex mutex)
(guarantee-thread-mutex mutex 'TRY-LOCK-THREAD-MUTEX)
(without-interrupts
(set-thread-mutex/owner! mutex thread)
(add-thread-mutex! thread mutex)
#t)))))
+\f
+(define (with-thread-mutex-lock mutex thunk)
+ (guarantee-thread-mutex mutex 'WITH-THREAD-MUTEX-LOCK)
+ (dynamic-wind (lambda () (lock-thread-mutex mutex))
+ thunk
+ (lambda () (unlock-thread-mutex mutex))))
+
+(define (without-thread-mutex-lock mutex thunk)
+ (guarantee-thread-mutex mutex 'WITH-THREAD-MUTEX-LOCK)
+ (dynamic-wind (lambda () (unlock-thread-mutex mutex))
+ thunk
+ (lambda () (lock-thread-mutex mutex))))
+
+;;; WITH-THREAD-MUTEX-LOCKED is retained for compatibility for old
+;;; programs that require recursion. For new programs, better to
+;;; refactor into clearer invariants that do not require recursion if
+;;; possible and use WITH-THREAD-MUTEX-LOCK to help detect lock order
+;;; mistakes.
(define (with-thread-mutex-locked mutex thunk)
(guarantee-thread-mutex mutex 'WITH-THREAD-MUTEX-LOCKED)