From 1b218c4ceb01500bed3d16346e9c5d3ef4fbcb19 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Thu, 23 Jul 2015 09:21:01 -0700 Subject: [PATCH] gdbm: Prepare the GC daemon to run concurrently with other threads. --- src/gdbm/gdbm.scm | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/gdbm/gdbm.scm b/src/gdbm/gdbm.scm index b94adc545..4ce2a21eb 100644 --- a/src/gdbm/gdbm.scm +++ b/src/gdbm/gdbm.scm @@ -345,23 +345,27 @@ USA. (loop (cdr alist))))))) (define (cleanup-open-gdbfs) - (if (not (thread-mutex-owner open-gdbfs-mutex)) - (let loop ((entries open-gdbfs) - (prev #f)) - (if (pair? entries) - (let ((entry (car entries)) - (next (cdr entries))) - (if (weak-pair/car? entry) - (loop next entries) - (let ((args (weak-cdr entry))) - (if prev - (set-cdr! prev next) - (set! open-gdbfs next)) - (if (not (alien-null? args)) - (begin - (C-call "do_gdbm_close" args) - (alien-null! args))) - (loop next prev)))))))) + (with-thread-mutex-try-lock + open-gdbfs-mutex + (lambda () + (let loop ((entries open-gdbfs) + (prev #f)) + (if (pair? entries) + (let ((entry (car entries)) + (next (cdr entries))) + (if (weak-pair/car? entry) + (loop next entries) + (let ((args (weak-cdr entry))) + (if prev + (set-cdr! prev next) + (set! open-gdbfs next)) + (if (not (alien-null? args)) + (begin + (C-call "do_gdbm_close" args) + (alien-null! args))) + (loop next prev))))))) + (lambda () + unspecific))) (define (reset-open-gdbfs) (for-each (lambda (weak) (alien-null! (weak-cdr weak))) open-gdbfs) -- 2.25.1