summaryrefslogtreecommitdiff
path: root/libguile/ports.c
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-02-28 17:56:58 -0500
committerMark H Weaver <mhw@netris.org>2013-03-05 16:04:55 -0500
commitf57ea23ac8e1436f37ceeda3ea8625243c20e645 (patch)
tree9770b54992f625abae89964d8b6efea62d09dea6 /libguile/ports.c
parent29ace173b170a5d77e6becb30fb1d9f253a373d5 (diff)
downloadguile-f57ea23ac8e1436f37ceeda3ea8625243c20e645.tar.gz
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.
Diffstat (limited to 'libguile/ports.c')
-rw-r--r--libguile/ports.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libguile/ports.c b/libguile/ports.c
index 55808e272..8737a7672 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -418,10 +418,14 @@ SCM_DEFINE (scm_current_error_port, "current-error-port", 0, 0, 0,
SCM
scm_current_warning_port (void)
{
- static SCM cwp_var = SCM_BOOL_F;
-
- if (scm_is_false (cwp_var))
- cwp_var = scm_c_private_lookup ("guile", "current-warning-port");
+ static SCM cwp_var = SCM_UNDEFINED;
+ static scm_i_pthread_mutex_t cwp_var_mutex
+ = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
+ scm_i_scm_pthread_mutex_lock (&cwp_var_mutex);
+ if (SCM_UNBNDP (cwp_var))
+ cwp_var = scm_c_private_variable ("guile", "current-warning-port");
+ scm_i_pthread_mutex_unlock (&cwp_var_mutex);
return scm_call_0 (scm_variable_ref (cwp_var));
}