[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 33/58: Module import obarrays are accessed in a critical
From: |
Andy Wingo |
Subject: |
[Guile-commits] 33/58: Module import obarrays are accessed in a critical section. |
Date: |
Tue, 7 Aug 2018 06:58:35 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit edc80bd595a442d059098fd6b605bbe1aa7e81ca
Author: Ludovic Courtès <address@hidden>
Date: Mon Jun 18 17:39:35 2018 +0200
Module import obarrays are accessed in a critical section.
Fixes <https://bugs.gnu.org/31879>.
* libguile/modules.c (import_obarray_mutex): New variable.
(resolve_duplicate_binding, module_imported_variable): Acquire it before
accessing an obarray.
---
libguile/modules.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/libguile/modules.c b/libguile/modules.c
index 751d907..b0327fc 100644
--- a/libguile/modules.c
+++ b/libguile/modules.c
@@ -275,6 +275,13 @@ default_duplicate_binding_handlers (void)
return (scm_call_0 (get_handlers));
}
+/* Each module has an "import obarray" that may be accessed concurrently
+ by several threads. This mutex protects access to any obarray. This
+ is coarse-grain but (1) pthread mutexes are quite cheap, and (2)
+ Scheme "programs" have a cache for free variables anyway. */
+static scm_i_pthread_mutex_t import_obarray_mutex =
+ SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
/* Resolve the import of SYM in MODULE, where SYM is currently provided by
both IFACE1 as VAR1 and IFACE2 as VAR2. Return the variable chosen by the
duplicate binding handlers or `#f'. */
@@ -300,7 +307,11 @@ resolve_duplicate_binding (SCM module, SCM sym,
args[5] = SCM_VARIABLE_REF (var2);
if (SCM_UNBNDP (args[5]))
args[5] = SCM_BOOL_F;
+
+ scm_i_pthread_mutex_lock (&import_obarray_mutex);
args[6] = scm_hashq_ref (SCM_MODULE_IMPORT_OBARRAY (module), sym,
SCM_BOOL_F);
+ scm_i_pthread_mutex_unlock (&import_obarray_mutex);
+
args[7] = SCM_BOOL_F;
handlers = SCM_MODULE_DUPLICATE_HANDLERS (module);
@@ -338,7 +349,11 @@ module_imported_variable (SCM module, SCM sym)
/* Search cached imported bindings. */
imports = SCM_MODULE_IMPORT_OBARRAY (module);
+
+ scm_i_pthread_mutex_lock (&import_obarray_mutex);
var = scm_hashq_ref (imports, sym, SCM_UNDEFINED);
+ scm_i_pthread_mutex_unlock (&import_obarray_mutex);
+
if (SCM_BOUND_THING_P (var))
return var;
@@ -386,7 +401,9 @@ module_imported_variable (SCM module, SCM sym)
if (SCM_BOUND_THING_P (found_var))
{
/* Save the lookup result for future reference. */
+ scm_i_pthread_mutex_lock (&import_obarray_mutex);
(void) scm_hashq_set_x (imports, sym, found_var);
+ scm_i_pthread_mutex_unlock (&import_obarray_mutex);
return found_var;
}
}
- [Guile-commits] 21/58: goops: Fix 'instance?' to work on objects that aren't structs., (continued)
- [Guile-commits] 21/58: goops: Fix 'instance?' to work on objects that aren't structs., Andy Wingo, 2018/08/07
- [Guile-commits] 10/58: build: Use 'sed' invocation compatible with BSD sed., Andy Wingo, 2018/08/07
- [Guile-commits] 24/58: Add copyright header for (language elisp falias), and fix typo., Andy Wingo, 2018/08/07
- [Guile-commits] 29/58: get-bytevector-n and get-bytevector-n! can now read more than 4 GB, Andy Wingo, 2018/08/07
- [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 <=
- [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, 2018/08/07
- [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