(%unlock))
(define (suspend-current-thread)
- (without-interrupts
- (lambda ()
- (%lock)
- (%suspend-thread first-running-thread))))
+ (set-interrupt-enables! interrupt-mask/in-threads)
+ (%lock)
+ (%assert first-running-thread "suspend-current-thread: no current thread")
+ (%suspend-thread first-running-thread))
(define (%suspend-thread thread)
(%assert-locked '%suspend-thread)
(call-with-current-continuation
(lambda (continuation)
(let ((thread first-running-thread))
+ (%assert thread "stop-current-thread: lost current thread")
(set-thread/continuation! thread continuation)
(maybe-save-thread-float-environment! thread)
(set-interrupt-enables! interrupt-mask/in-threads)
(define (yield-current-thread)
(without-interrupts
(lambda ()
+ (%lock)
(let ((thread first-running-thread))
- (%lock)
+ (%assert thread "yield-current-thread: no current thread")
;; Allow preemption now, since the current thread has
;; volunteered to yield control.
(set-thread/execution-state! thread 'RUNNING)
(define (join-thread thread event-constructor)
(guarantee-thread thread 'JOIN-THREAD)
- (let ((self (current-thread)))
+ (let ((self first-running-thread))
+ (%assert self "join-thread: no current thread")
(if (eq? thread self)
(signal-thread-deadlock self "join thread" join-thread thread)
(let ((mask (set-interrupt-enables! interrupt-mask/in-threads)))
(set-interrupt-enables! mask)
(signal-thread-event
self
- (event-constructor thread value)))))))))
+ ;; Executed in the dynamic state of SELF, not THREAD(!).
+ (event-constructor thread value)))))))))
(define (detach-thread thread)
(guarantee-thread thread 'DETACH-THREAD)
(with-thread-lock
(lambda ()
(let ((thread first-running-thread))
+ (%assert thread "unblock-thread-events: no current thread")
(handle-thread-events thread)
(set-thread/block-events?! thread #f)))))
(define (deregister-all-events)
(with-thread-lock
(lambda ()
- (let* ((thread first-running-thread)
+ (let* ((thread
+ (or first-running-thread
+ (%outf-error "deregister-all-events: no current thread")))
(block-events? (thread/block-events? thread)))
(set-thread/block-events?! thread #t)
(ring/discard-all (thread/pending-events thread))
(guarantee-thread-mutex mutex 'LOCK-THREAD-MUTEX)
(let ((mask (set-interrupt-enables! interrupt-mask/in-threads)))
(%lock)
- (let ((thread first-running-thread)
+ (let ((thread (or first-running-thread
+ (%outf-error "lock-thread-mutex: no current thread")))
(owner (thread-mutex/owner mutex)))
(if (eq? owner thread)
(begin
(guarantee-thread-mutex mutex 'UNLOCK-THREAD-MUTEX)
(let ((mask (set-interrupt-enables! interrupt-mask/in-threads)))
(%lock)
- (let ((owner (thread-mutex/owner mutex)))
- (if (and owner (not (eq? owner (current-thread))))
+ (let ((thread (or first-running-thread
+ (%outf-error "unlock-thread-mutex: no current thread")))
+ (owner (thread-mutex/owner mutex)))
+ (if (and owner (not (eq? owner thread)))
(begin
(%unlock)
(set-interrupt-enables! mask)
(with-thread-lock
(lambda ()
(and (not (thread-mutex/owner mutex))
- (let ((thread (current-thread)))
+ (let ((thread
+ (or first-running-thread
+ (%outf-error "try-lock-thread-mutex: no current thread"))))
(set-thread-mutex/owner! mutex thread)
(add-thread-mutex! thread mutex)
#t)))))