(define gc-finalizers-mutex)
(define (reset-gc-finalizers)
- (walk-gc-finalizers-list
+ (walk-gc-finalizers-list/unsafe
(lambda (finalizer)
- (with-thread-mutex-lock (gc-finalizer-mutex finalizer)
- (lambda ()
- (set-gc-finalizer-items! finalizer '()))))))
+ (set-gc-finalizer-items! finalizer '()))))
(define (run-gc-finalizers)
- (walk-gc-finalizers-list
- (lambda (finalizer)
- (let ((procedure (gc-finalizer-procedure finalizer)))
- (let loop ((items (gc-finalizer-items finalizer)) (prev #f))
- (if (pair? items)
- (if (weak-pair/car? (car items))
- (loop (cdr items) items)
- (let ((context (weak-cdr (car items)))
- (next (cdr items)))
- (if prev
- (set-cdr! prev next)
- (set-gc-finalizer-items! finalizer next))
- (procedure context)
- (loop next prev)))))))))
-
-(define (walk-gc-finalizers-list procedure)
- (with-thread-mutex-lock gc-finalizers-mutex
- (lambda ()
- (let loop ((finalizers gc-finalizers) (prev #f))
- (if (weak-pair? finalizers)
- (let ((finalizer (weak-car finalizers)))
- (if finalizer
- (begin
- (procedure finalizer)
- (loop (weak-cdr finalizers) finalizers))
- (let ((next (weak-cdr finalizers)))
- (if prev
- (weak-set-cdr! prev next)
- (set! gc-finalizers next))
- (loop next prev)))))))))
+ (with-thread-mutex-try-lock
+ gc-finalizers-mutex
+ (lambda ()
+ (walk-gc-finalizers-list/unsafe
+ (lambda (finalizer)
+ (let ((procedure (gc-finalizer-procedure finalizer)))
+ (let loop ((items (gc-finalizer-items finalizer)) (prev #f))
+ (if (pair? items)
+ (if (weak-pair/car? (car items))
+ (loop (cdr items) items)
+ (let ((context (weak-cdr (car items)))
+ (next (cdr items)))
+ (if prev
+ (set-cdr! prev next)
+ (set-gc-finalizer-items! finalizer next))
+ (procedure context)
+ (loop next prev)))))))))
+ (lambda ()
+ unspecific)))
+
+(define (walk-gc-finalizers-list/unsafe procedure)
+ (let loop ((finalizers gc-finalizers) (prev #f))
+ (if (weak-pair? finalizers)
+ (let ((finalizer (weak-car finalizers)))
+ (if finalizer
+ (begin
+ (procedure finalizer)
+ (loop (weak-cdr finalizers) finalizers))
+ (let ((next (weak-cdr finalizers)))
+ (if prev
+ (weak-set-cdr! prev next)
+ (set! gc-finalizers next))
+ (loop next prev)))))))
(define (initialize-package!)
(set! gc-finalizers '())