From 54d53055c21b3feb331d6fd39d08c2ef4b7114f3 Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Wed, 27 Dec 2000 15:43:15 +0000 Subject: [PATCH] Make the INI mechanism thread safe (or at least thread safer :) --- Zend/ZendTS.dsp | 4 +++ Zend/zend.c | 22 +++++++++++++++ Zend/zend_globals.h | 2 ++ Zend/zend_ini.c | 66 +++++++++++++++++++++++++++------------------ Zend/zend_ini.h | 14 +++++----- 5 files changed, 75 insertions(+), 33 deletions(-) diff --git a/Zend/ZendTS.dsp b/Zend/ZendTS.dsp index 435faf43ae..14c651e1c7 100644 --- a/Zend/ZendTS.dsp +++ b/Zend/ZendTS.dsp @@ -332,6 +332,10 @@ SOURCE=.\zend_ini_scanner.h # End Source File # Begin Source File +SOURCE=.\zend_istdiostream.h +# End Source File +# Begin Source File + SOURCE=".\zend_language_parser.h" # End Source File # Begin Source File diff --git a/Zend/zend.c b/Zend/zend.c index 8a1ab437fc..e5b392f39d 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -25,6 +25,7 @@ #include "zend_list.h" #include "zend_API.h" #include "zend_builtin_functions.h" +#include "zend_ini.h" #ifdef ZTS # define GLOBAL_FUNCTION_TABLE global_function_table @@ -307,6 +308,7 @@ static void executor_globals_dtor(zend_executor_globals *executor_globals) { zend_shutdown_constants(ELS_C); zend_destroy_rsrc_plist(ELS_C); + zend_ini_shutdown(ELS_C); } @@ -322,6 +324,17 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals) #include #endif +#ifdef ZTS +static void zend_new_thread_end_handler(THREAD_T thread_id) +{ + ELS_FETCH(); + + zend_copy_ini_directives(ELS_C); + zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP ELS_CC); +} +#endif + + int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions) { #ifdef ZTS @@ -399,6 +412,12 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i zend_startup_builtin_functions(); } + zend_ini_startup(ELS_C); + +#ifdef ZTS + tsrm_set_new_thread_end_handler(zend_new_thread_end_handler); +#endif + return SUCCESS; } @@ -517,6 +536,9 @@ void zend_deactivate(CLS_D ELS_DC) if (setjmp(EG(bailout))==0) { shutdown_compiler(CLS_C); } + if (setjmp(EG(bailout))==0) { + zend_ini_deactivate(ELS_C); + } } diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 50a2f6f069..ecbc13fc0e 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -191,6 +191,8 @@ struct _zend_executor_globals { int lambda_count; + HashTable ini_directives; + void *reserved[ZEND_MAX_RESERVED_RESOURCES]; #if SUPPORT_INTERACTIVE int interactive; diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index 7ee1a5d5e2..517b01b58a 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -25,7 +25,7 @@ #include "zend_alloc.h" #include "zend_operators.h" -static HashTable known_directives; +static HashTable *registered_zend_ini_directives; /* @@ -60,25 +60,39 @@ static int zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stage) /* * Startup / shutdown */ -int zend_ini_mstartup() +int zend_ini_startup(ELS_D) { - if (zend_hash_init_ex(&known_directives, 100, NULL, NULL, 1, 0)==FAILURE) { + registered_zend_ini_directives = &EG(ini_directives); + if (zend_hash_init_ex(registered_zend_ini_directives, 100, NULL, NULL, 1, 0)==FAILURE) { return FAILURE; } return SUCCESS; } -int zend_ini_mshutdown() +int zend_ini_shutdown(ELS_D) { - zend_hash_destroy(&known_directives); + zend_hash_destroy(&EG(ini_directives)); return SUCCESS; } -int zend_ini_rshutdown() +int zend_ini_deactivate(ELS_D) { - zend_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) zend_restore_ini_entry_cb, (void *) ZEND_INI_STAGE_DEACTIVATE); + zend_hash_apply_with_argument(&EG(ini_directives), (int (*)(void *, void *)) zend_restore_ini_entry_cb, (void *) ZEND_INI_STAGE_DEACTIVATE); + return SUCCESS; +} + + +int zend_copy_ini_directives(ELS_D) +{ + zend_ini_entry ini_entry; + + if (zend_hash_init_ex(&EG(ini_directives), registered_zend_ini_directives->nNumOfElements, NULL, NULL, 1, 0)==FAILURE) { + return FAILURE; + } + zend_hash_copy(&EG(ini_directives), registered_zend_ini_directives, NULL, &ini_entry, sizeof(zend_ini_entry)); + zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP ELS_CC); return SUCCESS; } @@ -103,9 +117,9 @@ static int ini_key_compare(const void *a, const void *b) } -void zend_ini_sort_entries(void) +void zend_ini_sort_entries(ELS_D) { - zend_hash_sort(&known_directives, qsort, ini_key_compare, 0); + zend_hash_sort(&EG(ini_directives), qsort, ini_key_compare, 0); } /* @@ -120,7 +134,7 @@ ZEND_API int zend_register_ini_entries(zend_ini_entry *ini_entry, int module_num while (p->name) { p->module_number = module_number; - if (zend_hash_add(&known_directives, p->name, p->name_length, p, sizeof(zend_ini_entry), (void **) &hashed_ini_entry)==FAILURE) { + if (zend_hash_add(registered_zend_ini_directives, p->name, p->name_length, p, sizeof(zend_ini_entry), (void **) &hashed_ini_entry)==FAILURE) { zend_unregister_ini_entries(module_number); return FAILURE; } @@ -143,7 +157,7 @@ ZEND_API int zend_register_ini_entries(zend_ini_entry *ini_entry, int module_num ZEND_API void zend_unregister_ini_entries(int module_number) { - zend_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) zend_remove_ini_entries, (void *) &module_number); + zend_hash_apply_with_argument(registered_zend_ini_directives, (int (*)(void *, void *)) zend_remove_ini_entries, (void *) &module_number); } @@ -156,9 +170,9 @@ static int zend_ini_refresh_cache(zend_ini_entry *p, int stage) } -ZEND_API void zend_ini_refresh_caches(int stage) +ZEND_API void zend_ini_refresh_caches(int stage ELS_DC) { - zend_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) zend_ini_refresh_cache, (void *)(long) stage); + zend_hash_apply_with_argument(&EG(ini_directives), (int (*)(void *, void *)) zend_ini_refresh_cache, (void *)(long) stage); } @@ -166,8 +180,9 @@ ZEND_API int zend_alter_ini_entry(char *name, uint name_length, char *new_value, { zend_ini_entry *ini_entry; char *duplicate; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==FAILURE) { return FAILURE; } @@ -199,8 +214,9 @@ ZEND_API int zend_alter_ini_entry(char *name, uint name_length, char *new_value, ZEND_API int zend_restore_ini_entry(char *name, uint name_length, int stage) { zend_ini_entry *ini_entry; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==FAILURE) { return FAILURE; } @@ -213,7 +229,7 @@ ZEND_API int zend_ini_register_displayer(char *name, uint name_length, void (*di { zend_ini_entry *ini_entry; - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) { + if (zend_hash_find(registered_zend_ini_directives, name, name_length, (void **) &ini_entry)==FAILURE) { return FAILURE; } @@ -230,8 +246,9 @@ ZEND_API int zend_ini_register_displayer(char *name, uint name_length, void (*di ZEND_API long zend_ini_long(char *name, uint name_length, int orig) { zend_ini_entry *ini_entry; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==SUCCESS) { if (orig && ini_entry->modified) { return (ini_entry->orig_value ? strtol(ini_entry->orig_value, NULL, 0) : 0); } else if (ini_entry->value) { @@ -246,8 +263,9 @@ ZEND_API long zend_ini_long(char *name, uint name_length, int orig) ZEND_API double zend_ini_double(char *name, uint name_length, int orig) { zend_ini_entry *ini_entry; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==SUCCESS) { if (orig && ini_entry->modified) { return (double) (ini_entry->orig_value ? strtod(ini_entry->orig_value, NULL) : 0.0); } else if (ini_entry->value) { @@ -262,8 +280,9 @@ ZEND_API double zend_ini_double(char *name, uint name_length, int orig) ZEND_API char *zend_ini_string(char *name, uint name_length, int orig) { zend_ini_entry *ini_entry; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==SUCCESS) { if (orig && ini_entry->modified) { return ini_entry->orig_value; } else { @@ -278,8 +297,9 @@ ZEND_API char *zend_ini_string(char *name, uint name_length, int orig) zend_ini_entry *get_ini_entry(char *name, uint name_length) { zend_ini_entry *ini_entry; + ELS_FETCH(); - if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) { + if (zend_hash_find(&EG(ini_directives), name, name_length, (void **) &ini_entry)==SUCCESS) { return ini_entry; } else { return NULL; @@ -375,12 +395,6 @@ ZEND_INI_DISP(display_link_numbers) } -ZEND_API void zend_ini_apply_with_argument(apply_func_arg_t apply_func, void *arg) -{ - zend_hash_apply_with_argument(&known_directives, apply_func, arg); -} - - /* Standard message handlers */ ZEND_API ZEND_INI_MH(OnUpdateBool) diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h index d50144b809..a14a91722f 100644 --- a/Zend/zend_ini.h +++ b/Zend/zend_ini.h @@ -52,15 +52,17 @@ struct _zend_ini_entry { }; -int zend_ini_mstartup(void); -int zend_ini_mshutdown(void); -int zend_ini_rshutdown(void); +int zend_ini_startup(ELS_D); +int zend_ini_shutdown(ELS_D); +int zend_ini_deactivate(ELS_D); -void zend_ini_sort_entries(void); +int zend_copy_ini_directives(ELS_D); + +void zend_ini_sort_entries(ELS_D); ZEND_API int zend_register_ini_entries(zend_ini_entry *ini_entry, int module_number); ZEND_API void zend_unregister_ini_entries(int module_number); -ZEND_API void zend_ini_refresh_caches(int stage); +ZEND_API void zend_ini_refresh_caches(int stage ELS_DC); ZEND_API int zend_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type, int stage); ZEND_API int zend_restore_ini_entry(char *name, uint name_length, int stage); ZEND_API void display_ini_entries(zend_module_entry *module); @@ -72,8 +74,6 @@ zend_ini_entry *get_ini_entry(char *name, uint name_length); ZEND_API int zend_ini_register_displayer(char *name, uint name_length, void (*displayer)(zend_ini_entry *ini_entry, int type)); -ZEND_API void zend_ini_apply_with_argument(apply_func_arg_t apply_func, void *arg); - ZEND_API ZEND_INI_DISP(zend_ini_boolean_displayer_cb); ZEND_API ZEND_INI_DISP(zend_ini_color_displayer_cb); ZEND_API ZEND_INI_DISP(display_link_numbers); -- 2.50.1