diff options
author | Mark H Weaver <mhw@netris.org> | 2014-01-23 11:37:36 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-01-23 23:44:11 -0500 |
commit | 60617d819d77a1b92ed6c557a0b49b8e9a8e97b9 (patch) | |
tree | dd3ec4a2bd0b1f85c9805a2abbf0437782f1de45 /libguile/strings.c | |
parent | f6ddf827f8f192af7a8cd255bd8374a0d38bbb74 (diff) | |
download | guile-60617d819d77a1b92ed6c557a0b49b8e9a8e97b9.tar.gz |
Fix thread-unsafe lazy initializations.
* libguile/backtrace.c (print_exception_var): New static variable.
(init_print_exception_var): New static function.
(scm_print_exception): Remove thread-unsafe lazy initialization.
Call 'init_print_exception_var' using 'scm_i_pthread_once'.
Use 'print_exception_var'.
* libguile/continuations.c (call_cc): New static variable.
(init_call_cc): New static function.
(scm_i_call_with_current_continuation): Remove thread-unsafe lazy
initialization. Call 'init_call_cc' using 'scm_i_pthread_once'.
* libguile/debug.c (local_eval_var): New static variable.
(init_local_eval_var): New static function.
(scm_local_eval): Remove lazy initialization using mutexes.
Call 'init_local_eval_var' using 'scm_i_pthread_once'.
Use 'scm_variable_ref' instead of 'SCM_VARIABLE_REF'.
* libguile/eval.c (map_var, for_each_var): New static variables.
(init_map_var, init_for_each_var): New static functions.
(scm_map, scm_for_each): Remove thread-unsafe lazy initializations.
Call 'init_map_var' (or 'init_for_each_var') using 'scm_i_pthread_once'.
Use 'map_var' (or 'for_each_var').
* libguile/frames.c (frame_arguments_var): New static variable.
(init_frame_arguments_var): New static function.
(scm_frame_arguments): Remove thread-unsafe lazy initialization.
Call 'init_frame_arguments_var' using 'scm_i_pthread_once'.
Use 'frame_arguments_var'. Use 'scm_variable_ref' instead of
'SCM_VARIABLE_REF'.
* libguile/goops.c (delayed_compile_var): New static variable.
(init_delayed_compile_var): New static function.
(make_dispatch_procedure): Remove thread-unsafe lazy initialization.
Call 'init_delayed_compile_var' using 'scm_i_pthread_once'.
Use 'delayed_compile_var'. Use 'scm_variable_ref' instead of
'SCM_VARIABLE_REF'.
* libguile/instructions.c (instructions_by_name): New static variable.
(init_instructions_by_name): New static function.
(scm_lookup_instruction_by_name): Remove thread-unsafe lazy
initialization. Call 'init_instructions_by_name' using
'scm_i_pthread_once'.
* libguile/ports.c (current_warning_port_var)
(current_warning_port_once): New static variables.
(init_current_warning_port_var): New static function.
(scm_current_warning_port): Remove lazy initialization using mutexes.
Call 'init_current_warning_port_var' using 'scm_i_pthread_once'.
Use 'current_warning_port_var'.
(scm_set_current_warning_port): Remove thread-unsafe lazy initialization.
Call 'init_current_warning_port_var' using 'scm_i_pthread_once'.
Use 'current_warning_port_var'.
* libguile/strings.c (null_stringbuf): New static variable.
(init_null_stringbuf): New static function.
(scm_i_make_string): Remove thread-unsafe lazy initialization.
Call 'init_null_stringbuf' using 'scm_i_pthread_once'.
* libguile/strports.c (eval_string_var, k_module): New static variables.
(init_eval_string_var_and_k_module): New static function.
(scm_eval_string_in_module): Remove lazy initialization using mutexes.
Call 'init_eval_string_var_and_k_module' using 'scm_i_pthread_once'.
Use 'eval_string_var'.
* libguile/throw.c (CACHE_VAR): Remove incorrect macro.
(catch_var, throw_var, with_throw_handler_var): New static variables.
(scm_catch, scm_catch_with_pre_unwind_handler): Remove thread-unsafe
lazy initialization. Use 'catch_var'.
(init_with_throw_handler_var): New static function.
(scm_with_throw_handler): Remove thread-unsafe lazy initialization.
Call 'init_with_throw_handler_var' using 'scm_i_pthread_once'.
Use 'with_throw_handler_var'.
(scm_throw): Remove thread-unsafe lazy initialization.
Use 'throw_var'.
(scm_init_throw): Initialize 'catch_var' and 'throw_var'.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 1b241e52c..cab5d0572 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -260,6 +260,15 @@ scm_i_pthread_mutex_t stringbuf_write_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; SCM scm_nullstr; +static SCM null_stringbuf; + +static void +init_null_stringbuf (void) +{ + null_stringbuf = make_stringbuf (0); + SET_STRINGBUF_SHARED (null_stringbuf); +} + /* Create a scheme string with space for LEN 8-bit Latin-1-encoded characters. CHARSP, if not NULL, will be set to location of the char array. If READ_ONLY_P, the returned string is read-only; @@ -267,17 +276,13 @@ SCM scm_nullstr; SCM scm_i_make_string (size_t len, char **charsp, int read_only_p) { - static SCM null_stringbuf = SCM_BOOL_F; SCM buf; SCM res; if (len == 0) { - if (SCM_UNLIKELY (scm_is_false (null_stringbuf))) - { - null_stringbuf = make_stringbuf (0); - SET_STRINGBUF_SHARED (null_stringbuf); - } + static scm_i_pthread_once_t once = SCM_I_PTHREAD_ONCE_INIT; + scm_i_pthread_once (&once, init_null_stringbuf); buf = null_stringbuf; } else |