mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Fix thread-unsafe lazy initializations.
* libguile/debug.c (scm_local_eval): libguile/ports.c (scm_current_warning_port): libguile/strports.c (scm_eval_string_in_module): Perform lazy-initialization while holding a mutex. Use SCM_UNDEFINED as the uninitialized value. Use 'scm_c_*_variable'. * doc/ref/api-modules.texi (Accessing Modules from C): Fix 'my_eval_string' example to be thread-safe.
This commit is contained in:
parent
29ace173b1
commit
f57ea23ac8
4 changed files with 29 additions and 14 deletions
|
@ -211,10 +211,14 @@ SCM_DEFINE (scm_debug_hang, "debug-hang", 0, 1, 0,
|
|||
SCM
|
||||
scm_local_eval (SCM exp, SCM env)
|
||||
{
|
||||
static SCM local_eval_var = SCM_BOOL_F;
|
||||
static SCM local_eval_var = SCM_UNDEFINED;
|
||||
static scm_i_pthread_mutex_t local_eval_var_mutex
|
||||
= SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
if (scm_is_false (local_eval_var))
|
||||
scm_i_scm_pthread_mutex_lock (&local_eval_var_mutex);
|
||||
if (SCM_UNBNDP (local_eval_var))
|
||||
local_eval_var = scm_c_public_variable ("ice-9 local-eval", "local-eval");
|
||||
scm_i_pthread_mutex_unlock (&local_eval_var_mutex);
|
||||
|
||||
return scm_call_2 (SCM_VARIABLE_REF (local_eval_var), exp, env);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue