From: Matt Birkholz Date: Wed, 19 Aug 2015 01:00:50 +0000 (-0700) Subject: Use without-interruption and more locking(!) in gcfinal.scm. X-Git-Tag: mit-scheme-pucked-9.2.12~376^2~29 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=9db45d678c26326a415366ab60e545c8d4f43d2f;p=mit-scheme.git Use without-interruption and more locking(!) in gcfinal.scm. Prepare the GC daemon to run concurrently with other threads; lock each finalizer while it is cleaned in run-gc-finalizers. Add without-interruption to add-to-, remove-from-, remove-all-from-, with--lock, and make-gc-finalized-object, NOT to search- or -elements. Reset-gc-finalizers also lost its without-interrupts, but it is an after-restore event already executed without-interrupts. --- diff --git a/src/runtime/gcfinal.scm b/src/runtime/gcfinal.scm index e51673148..4f88e18b5 100644 --- a/src/runtime/gcfinal.scm +++ b/src/runtime/gcfinal.scm @@ -70,7 +70,7 @@ USA. (error:wrong-type-argument object "finalized object" 'ADD-TO-GC-FINALIZER!)) - (with-thread-mutex-lock (gc-finalizer-mutex finalizer) + (with-finalizer-lock finalizer (lambda () (let ((context ((gc-finalizer-object-context finalizer) object))) (if (not context) @@ -87,7 +87,7 @@ USA. (error:wrong-type-argument object "finalized object" 'REMOVE-FROM-GC-FINALIZER!))) - (with-thread-mutex-lock (gc-finalizer-mutex finalizer) + (with-finalizer-lock finalizer (lambda () (remove-from-locked-gc-finalizer! finalizer object)))) @@ -110,16 +110,22 @@ USA. (procedure context)) (loop (cdr items) items)))))) +(define (with-finalizer-lock finalizer thunk) + (with-thread-mutex-lock + (gc-finalizer-mutex finalizer) + (lambda () + (without-interruption thunk)))) + (define (with-gc-finalizer-lock finalizer thunk) (guarantee-gc-finalizer finalizer 'WITH-GC-FINALIZER-LOCK) - (with-thread-mutex-lock (gc-finalizer-mutex finalizer) thunk)) + (with-finalizer-lock finalizer thunk)) (define (remove-all-from-gc-finalizer! finalizer) (guarantee-gc-finalizer finalizer 'REMOVE-ALL-FROM-GC-FINALIZER!) (let ((procedure (gc-finalizer-procedure finalizer)) (object-context (gc-finalizer-object-context finalizer)) (set-object-context! (gc-finalizer-set-object-context! finalizer))) - (with-thread-mutex-lock (gc-finalizer-mutex finalizer) + (with-finalizer-lock finalizer (lambda () (let loop () (let ((items (gc-finalizer-items finalizer))) @@ -172,7 +178,7 @@ USA. (get-context p) (let ((context (weak-cdr p))) (let ((object (context->object context))) - (with-thread-mutex-lock (gc-finalizer-mutex finalizer) + (with-finalizer-lock finalizer (lambda () (weak-set-car! p object) (set-gc-finalizer-items! @@ -199,18 +205,20 @@ USA. (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))))))))) + (with-finalizer-lock finalizer + (lambda () + (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)))