(define (remove-from-gc-finalizer! finalizer object)
(guarantee-gc-finalizer finalizer 'REMOVE-FROM-GC-FINALIZER!)
- (let ((procedure (gc-finalizer-procedure finalizer))
- (object? (gc-finalizer-object? finalizer))
- (object-context (gc-finalizer-object-context finalizer))
- (set-object-context! (gc-finalizer-set-object-context! finalizer)))
+ (let ((object? (gc-finalizer-object? finalizer)))
(if (not (object? object))
(error:wrong-type-argument object
"finalized object"
- 'REMOVE-FROM-GC-FINALIZER!))
- (with-thread-mutex-lock (gc-finalizer-mutex finalizer)
- (lambda ()
- (let ((context (object-context object)))
- (if (not context)
- (error:bad-range-argument object 'REMOVE-FROM-GC-FINALIZER!))
- (let loop ((items (gc-finalizer-items finalizer)) (prev #f))
- (if (not (pair? items))
- (error:bad-range-argument object 'REMOVE-FROM-GC-FINALIZER!))
- (if (eq? object (weak-car (car items)))
- (let ((next (cdr items)))
- (if prev
- (set-cdr! prev next)
- (set-gc-finalizer-items! finalizer next))
- (set-object-context! object #f)
- (procedure context))
- (loop (cdr items) items))))))))
+ 'REMOVE-FROM-GC-FINALIZER!)))
+ (with-thread-mutex-lock (gc-finalizer-mutex finalizer)
+ (lambda ()
+ (remove-from-locked-gc-finalizer! finalizer object))))
+
+(define (remove-from-locked-gc-finalizer! finalizer object)
+ (let ((procedure (gc-finalizer-procedure finalizer))
+ (object-context (gc-finalizer-object-context finalizer))
+ (set-object-context! (gc-finalizer-set-object-context! finalizer)))
+ (let ((context (object-context object)))
+ (if (not context)
+ (error:bad-range-argument object 'REMOVE-FROM-GC-FINALIZER!))
+ (let loop ((items (gc-finalizer-items finalizer)) (prev #f))
+ (if (not (pair? items))
+ (error:bad-range-argument object 'REMOVE-FROM-GC-FINALIZER!))
+ (if (eq? object (weak-car (car items)))
+ (let ((next (cdr items)))
+ (if prev
+ (set-cdr! prev next)
+ (set-gc-finalizer-items! finalizer next))
+ (set-object-context! object #f)
+ (procedure context))
+ (loop (cdr items) items))))))
+
+(define (with-gc-finalizer-lock finalizer thunk)
+ (guarantee-gc-finalizer finalizer 'WITH-GC-FINALIZER-LOCK)
+ (with-thread-mutex-lock (gc-finalizer-mutex finalizer) thunk))
\f
(define (remove-all-from-gc-finalizer! finalizer)
(guarantee-gc-finalizer finalizer 'REMOVE-ALL-FROM-GC-FINALIZER!)
(eq? 'OS/2-CONSOLE type))))
(define (channel-close channel)
- (without-interrupts
- (lambda ()
- (if (channel-open? channel)
- (begin
- (%deregister-io-descriptor (channel-descriptor-for-select channel))
- (remove-from-gc-finalizer! open-channels channel))))))
+ (with-gc-finalizer-lock open-channels
+ (lambda ()
+ (if (channel-open? channel)
+ (begin
+ (%deregister-io-descriptor (channel-descriptor-for-select channel))
+ (remove-from-locked-gc-finalizer! open-channels channel))))))
(define-integrable (channel-open? channel)
(if (channel-descriptor channel) #t #f))
\f
(define (channel-read channel buffer start end)
(let loop ()
- (let ((n (without-interrupts
- (lambda ()
- (if (channel-closed? channel)
- 0
- (%channel-read channel buffer start end))))))
+ (let ((n (%channel-read channel buffer start end)))
(if (eq? n #t)
(begin
(handle-subprocess-status-change)
- (without-interrupts
- (lambda ()
- (if (and (channel-open? channel)
- (channel-blocking? channel))
- (loop)
- #f))))
+ (if (channel-blocking? channel)
+ (loop)
+ #f))
n))))
(define (%channel-read channel buffer start end)
(define (channel-write channel buffer start end)
(let loop ()
- (let ((n (without-interrupts
- (lambda ()
- (if (channel-closed? channel)
- 0
- (%channel-write channel buffer start end))))))
+ (let ((n (%channel-write channel buffer start end)))
(if (eq? n #t)
(begin
(handle-subprocess-status-change)
- (without-interrupts
- (lambda ()
- (if (and (channel-open? channel)
- (channel-blocking? channel))
- (loop)
- #f))))
+ (if (channel-blocking? channel)
+ (loop)
+ #f))
n))))
(define (%channel-write channel buffer start end)
(thunk)))
(define (channel-table)
- (without-interrupts
- (lambda ()
- (let ((descriptors ((ucode-primitive channel-table 0))))
- (and descriptors
- (vector-map (lambda (descriptor)
- (or (descriptor->channel descriptor)
- (make-channel descriptor)))
- descriptors))))))
+ (with-gc-finalizer-lock open-channels
+ (lambda ()
+ (let ((descriptors ((ucode-primitive channel-table 0))))
+ (and descriptors
+ (vector-map descriptor->channel descriptors))))))
(define (channel-synchronize channel)
((ucode-primitive channel-synchronize 1) (channel-descriptor channel)))
;;;; Terminal Primitives
(define (tty-input-channel)
- (without-interrupts
- (lambda ()
- (make-channel ((ucode-primitive tty-input-channel 0))))))
+ (make-channel ((ucode-primitive tty-input-channel 0))))
(define (tty-output-channel)
- (without-interrupts
- (lambda ()
- (make-channel ((ucode-primitive tty-output-channel 0))))))
+ (make-channel ((ucode-primitive tty-output-channel 0))))
(define (terminal-get-state channel)
((ucode-primitive terminal-get-state 1) (channel-descriptor channel)))
;;;; PTY Master Primitives
(define (open-pty-master)
- (without-interrupts
+ (without-interruption
(lambda ()
(let ((result ((ucode-primitive open-pty-master 0))))
(values (make-channel (vector-ref result 0))
(define-guarantee directory-channel "directory channel")
(define (directory-channel-open name)
- (without-interrupts
+ (without-interruption
(lambda ()
(add-to-gc-finalizer! open-directories
(make-directory-channel
(length #f))
(define (make-select-registry)
- (without-interrupts
+ (without-interruption
(lambda ()
(add-to-gc-finalizer! select-registry-finalizer
(%make-select-registry
(and pathname (->namestring pathname))
p)
(let ((handle (make-dld-handle pathname (weak-cdr p))))
- (without-interrupts
+ (with-thread-mutex-lock dld-handles-mutex
(lambda ()
(set! dld-handles (cons handle dld-handles))
(weak-set-car! p #t)
(weak-set-cdr! p #f)))))))
\f
(define dld-handles)
+(define dld-handles-mutex)
(define (reset-dld-handles!)
(set! dld-handles '())
+ (set! dld-handles-mutex (make-thread-mutex))
unspecific)
(define (dld-unload-file handle)
(guarantee-dld-handle handle 'DLD-UNLOAD-FILE)
- (without-interrupts
+ (with-thread-mutex-lock dld-handles-mutex
(lambda ()
(%dld-unload-file handle)
(set! dld-handles (delq! handle dld-handles))
(pathname=? pathname* pathname))))))
(define (find-dld-handle predicate)
- (find-matching-item dld-handles predicate))
+ (with-thread-mutex-lock dld-handles-mutex
+ (lambda ()
+ (find-matching-item dld-handles predicate))))
(define (all-dld-handles)
- (list-copy dld-handles))
\ No newline at end of file
+ (with-thread-mutex-lock dld-handles-mutex
+ (lambda ()
+ (list-copy dld-handles))))
\ No newline at end of file
((nt)
(extend-package (runtime os-primitives)
(files "ntprm")
+ (import (runtime primitive-io)
+ channel-descriptor-for-select
+ tty-input-channel)
(export ()
console-channel-descriptor
delete-environment-variable!
(define-package (runtime console-i/o-port)
(files "ttyio")
(parent (runtime))
+ (import (runtime primitive-io)
+ tty-input-channel
+ tty-output-channel)
(export ()
console-i/o-port
console-i/o-port?
channel-blocking?
channel-close
channel-closed?
- channel-descriptor-for-select
channel-file-length
channel-file-position
channel-file-set-position
terminal-set-state
test-for-io-on-channel
test-for-io-on-descriptor
- tty-input-channel
- tty-output-channel
with-channel-blocking)
(export (runtime emacs-interface)
channel-descriptor)
test-select-registry)
(import (runtime thread)
%deregister-io-descriptor)
+ (import (runtime gc-finalizer)
+ with-gc-finalizer-lock
+ remove-from-locked-gc-finalizer!)
(export (runtime directory)
directory-channel/descriptor)
(initialization (initialize-package!)))