[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 27/58: Make module autoloading thread-safe.
From: |
Andy Wingo |
Subject: |
[Guile-commits] 27/58: Make module autoloading thread-safe. |
Date: |
Tue, 7 Aug 2018 06:58:34 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit 251202fc90f4dc22350cd9b2d85546e650391ee5
Author: Ludovic Courtès <address@hidden>
Date: Mon Jun 18 13:42:22 2018 +0200
Make module autoloading thread-safe.
Fixes <https://bugs.gnu.org/31878>.
* module/ice-9/boot-9.scm (call-with-module-autoload-lock): New procedure.
(try-module-autoload): Wrap body in 'call-with-module-autoload-lock'.
* module/ice-9/threads.scm: Set (@ (guile) call-with-module-autoload-lock).
---
module/ice-9/boot-9.scm | 72 ++++++++++++++++++++++++++----------------------
module/ice-9/threads.scm | 11 +++++++-
2 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 09eb871..ad911b9 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -2936,8 +2936,11 @@ module '(ice-9 q) '(make-q q-length))}."
;;; {Autoloading modules}
;;;
-;;; XXX FIXME autoloads-in-progress and autoloads-done
-;;; are not handled in a thread-safe way.
+(define (call-with-module-autoload-lock thunk)
+ ;; This binding is overridden when (ice-9 threads) is available to
+ ;; implement a critical section around the call to THUNK. It must be
+ ;; used anytime the autoload variables below are used.
+ (thunk))
(define autoloads-in-progress '())
@@ -2957,37 +2960,40 @@ but it fails to load."
file-name-separator-string))
dir-hint-module-name))))
(resolve-module dir-hint-module-name #f)
- (and (not (autoload-done-or-in-progress? dir-hint name))
- (let ((didit #f))
- (dynamic-wind
- (lambda () (autoload-in-progress! dir-hint name))
- (lambda ()
- (with-fluids ((current-reader #f))
- (save-module-excursion
- (lambda ()
- (define (call/ec proc)
- (let ((tag (make-prompt-tag)))
- (call-with-prompt
- tag
- (lambda ()
- (proc (lambda () (abort-to-prompt tag))))
- (lambda (k) (values)))))
- ;; The initial environment when loading a module is a fresh
- ;; user module.
- (set-current-module (make-fresh-user-module))
- ;; Here we could allow some other search strategy (other
than
- ;; primitive-load-path), for example using versions encoded
- ;; into the file system -- but then we would have to figure
- ;; out how to locate the compiled file, do auto-compilation,
- ;; etc. Punt for now, and don't use versions when locating
- ;; the file.
- (call/ec
- (lambda (abort)
- (primitive-load-path (in-vicinity dir-hint name)
- abort)
- (set! didit #t)))))))
- (lambda () (set-autoloaded! dir-hint name didit)))
- didit))))
+
+ (call-with-module-autoload-lock
+ (lambda ()
+ (and (not (autoload-done-or-in-progress? dir-hint name))
+ (let ((didit #f))
+ (dynamic-wind
+ (lambda () (autoload-in-progress! dir-hint name))
+ (lambda ()
+ (with-fluids ((current-reader #f))
+ (save-module-excursion
+ (lambda ()
+ (define (call/ec proc)
+ (let ((tag (make-prompt-tag)))
+ (call-with-prompt
+ tag
+ (lambda ()
+ (proc (lambda () (abort-to-prompt tag))))
+ (lambda (k) (values)))))
+ ;; The initial environment when loading a module is a
fresh
+ ;; user module.
+ (set-current-module (make-fresh-user-module))
+ ;; Here we could allow some other search strategy
(other than
+ ;; primitive-load-path), for example using versions
encoded
+ ;; into the file system -- but then we would have to
figure
+ ;; out how to locate the compiled file, do
auto-compilation,
+ ;; etc. Punt for now, and don't use versions when
locating
+ ;; the file.
+ (call/ec
+ (lambda (abort)
+ (primitive-load-path (in-vicinity dir-hint name)
+ abort)
+ (set! didit #t)))))))
+ (lambda () (set-autoloaded! dir-hint name didit)))
+ didit))))))
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index 65108d9..c42bd26 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -1,5 +1,5 @@
;;;; Copyright (C) 1996, 1998, 2001, 2002, 2003, 2006, 2010, 2011,
-;;;; 2012 Free Software Foundation, Inc.
+;;;; 2012, 2018 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -380,4 +380,13 @@ of applying P-PROC on ARGLISTS."
(loop))))))
threads)))))
+
+;; Now that thread support is loaded, make module autoloading
+;; thread-safe.
+(set! (@ (guile) call-with-module-autoload-lock)
+ (let ((mutex (make-mutex 'recursive)))
+ (lambda (thunk)
+ (with-mutex mutex
+ (thunk)))))
+
;;; threads.scm ends here
- [Guile-commits] 26/58: tests: Add SRFI-71 test., (continued)
- [Guile-commits] 26/58: tests: Add SRFI-71 test., Andy Wingo, 2018/08/07
- [Guile-commits] 34/58: Add 'scm_to_stringn' shortcut when converting to UTF-8., Andy Wingo, 2018/08/07
- [Guile-commits] 12/58: srfi-18: When timeout is a number, it's a relative number of seconds., Andy Wingo, 2018/08/07
- [Guile-commits] 22/58: Fix error reporting in 'load-thunk-from-memory'., Andy Wingo, 2018/08/07
- [Guile-commits] 19/58: Fix type inference for bitwise logical operators., Andy Wingo, 2018/08/07
- [Guile-commits] 23/58: elisp: Fix cross-compilation support., Andy Wingo, 2018/08/07
- [Guile-commits] 33/58: Module import obarrays are accessed in a critical section., Andy Wingo, 2018/08/07
- [Guile-commits] 38/58: GDB support: Fix 'display-vm-frames'., Andy Wingo, 2018/08/07
- [Guile-commits] 41/58: linker: Don't rely on out-of-range bv-ref exceptions., Andy Wingo, 2018/08/07
- [Guile-commits] 40/58: GDB support: Add 'guile-backtrace' command., Andy Wingo, 2018/08/07
- [Guile-commits] 27/58: Make module autoloading thread-safe.,
Andy Wingo <=
- [Guile-commits] 51/58: compile: Improve error message., Andy Wingo, 2018/08/07
- [Guile-commits] 28/58: vm: Fix typo when checking for 'madvise' error code., Andy Wingo, 2018/08/07
- [Guile-commits] 30/58: doc: Fix typo., Andy Wingo, 2018/08/07
- [Guile-commits] 36/58: vm: Fix another typo., Andy Wingo, 2018/08/07
- [Guile-commits] 32/58: tests: Adjust i18n.test to 'fr_FR.utf8' locale in glibc 2.27., Andy Wingo, 2018/08/07
- [Guile-commits] 39/58: GDB support: Add note about (gdb frame-filters)., Andy Wingo, 2018/08/07
- [Guile-commits] 31/58: doc: Document (ice-9 match) macros., Andy Wingo, 2018/08/07
- [Guile-commits] 49/58: r6rs-ports: Accept 'port-position' values greater than 2^32., Andy Wingo, 2018/08/07
- [Guile-commits] 45/58: Update NEWS., Andy Wingo, 2018/08/07
- [Guile-commits] 58/58: Add missing include to adapt to recent merge from master, Andy Wingo, 2018/08/07