]> granicus.if.org Git - php/commitdiff
Make the INI mechanism thread safe (or at least thread safer :)
authorZeev Suraski <zeev@php.net>
Wed, 27 Dec 2000 15:43:15 +0000 (15:43 +0000)
committerZeev Suraski <zeev@php.net>
Wed, 27 Dec 2000 15:43:15 +0000 (15:43 +0000)
Zend/ZendTS.dsp
Zend/zend.c
Zend/zend_globals.h
Zend/zend_ini.c
Zend/zend_ini.h

index 435faf43aee7bd9b937edf66019afa7b833e8bfa..14c651e1c766c4f01a8374af1b68259f0caca3ca 100644 (file)
@@ -332,6 +332,10 @@ SOURCE=.\zend_ini_scanner.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\zend_istdiostream.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=".\zend_language_parser.h"\r
 # End Source File\r
 # Begin Source File\r
index 8a1ab437fc584dc16f464d0d4135e863b06f1315..e5b392f39d71cebcb9718dd6b1b40ceaddaa7fe2 100644 (file)
@@ -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 <floatingpoint.h>
 #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);
+       }
 }
 
 
index 50a2f6f06951b279e4250a9174560795c8b5206b..ecbc13fc0eb76212a8d579b3d71634ae640277fb 100644 (file)
@@ -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;
index 7ee1a5d5e21aea7b832651f8b4c7afc3fec0a9f3..517b01b58ad860bb2133a1efa150020e01f0b32c 100644 (file)
@@ -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)
index d50144b8091d5e22bafd653f5cf1260527f1c843..a14a91722f1ae5a2c7bfc019f8672a726739dcd0 100644 (file)
@@ -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);