From 4c97b6c8cf7e9ff56be6511c9e4f40af1562b835 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 15 Feb 2013 17:35:58 +0400 Subject: [PATCH] "locked" must be a "module" global (local to thread) --- ZendAccelerator.h | 1 + zend_shared_alloc.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ZendAccelerator.h b/ZendAccelerator.h index 918e48fa14..36f1b548fd 100644 --- a/ZendAccelerator.h +++ b/ZendAccelerator.h @@ -231,6 +231,7 @@ typedef struct _zend_accel_globals { int internal_functions_count; int counted; /* the process uses shatred memory */ zend_bool enabled; + zend_bool locked; /* thread obtained exclusive lock */ HashTable bind_hash; /* prototype and zval lookup table */ zend_accel_directives accel_directives; char *cwd; /* current working directory or NULL */ diff --git a/zend_shared_alloc.c b/zend_shared_alloc.c index 12bfef20af..c4e0e55c79 100644 --- a/zend_shared_alloc.c +++ b/zend_shared_alloc.c @@ -43,7 +43,6 @@ #define S_H(s) g_shared_alloc_handler->s /* True globals */ -static zend_bool locked; /* old/new mapping. We can use true global even for ZTS because its usage is wrapped with exclusive lock anyway */ static HashTable xlat_table; @@ -214,7 +213,7 @@ int zend_shared_alloc_startup(int requested_size) shared_segments_array_size = ZSMMG(shared_segments_count)*S_H(segment_type_size)(); /* move shared_segments and shared_free to shared memory */ - locked = 1; /* no need to perform a real lock at this point */ + ZCG(locked) = 1; /* no need to perform a real lock at this point */ p_tmp_shared_globals = (zend_smm_shared_globals *) zend_shared_alloc(sizeof(zend_smm_shared_globals)); tmp_shared_segments = zend_shared_alloc(shared_segments_array_size+ZSMMG(shared_segments_count)*sizeof(void *)); @@ -227,7 +226,7 @@ int zend_shared_alloc_startup(int requested_size) ZSMMG(shared_segments) = tmp_shared_segments; ZSMMG(shared_memory_state).positions = (int *) zend_shared_alloc(sizeof(int)*ZSMMG(shared_segments_count)); - locked = 0; + ZCG(locked) = 0; return res; } @@ -255,7 +254,6 @@ void zend_shared_alloc_shutdown(void) #ifndef ZEND_WIN32 close(lock_file); #endif - locked = 0; } #define SHARED_ALLOC_FAILED() { \ @@ -270,9 +268,10 @@ void *zend_shared_alloc(size_t size) { int i; unsigned int block_size = size+sizeof(zend_shared_memory_block_header); + TSRMLS_FETCH(); #if 1 - if (!locked) { + if (!ZCG(locked)) { zend_accel_error(ACCEL_LOG_ERROR, "Shared memory lock not obtained"); } #endif @@ -334,7 +333,7 @@ void *_zend_shared_memdup(void *source, size_t size, zend_bool free_source TSRML void zend_shared_alloc_safe_unlock(TSRMLS_D) { - if (locked) { + if (ZCG(locked)) { zend_shared_alloc_unlock(TSRMLS_C); } } @@ -373,7 +372,7 @@ void zend_shared_alloc_lock(TSRMLS_D) zend_shared_alloc_lock_win32(); #endif - locked=1; + ZCG(locked) = 1; /* Prepare translation table * @@ -389,7 +388,7 @@ void zend_shared_alloc_unlock(TSRMLS_D) /* Destroy translation table */ zend_hash_destroy(&xlat_table); - locked=0; + ZCG(locked) = 0; #ifndef ZEND_WIN32 if (fcntl(lock_file, F_SETLK, &mem_write_unlock) == -1) { -- 2.40.0