threaded web server

From: Date: Thu, 07 Oct 1999 12:21:51 +0000
Subject: threaded web server
Groups: php.version4 
Request: Send a blank email to php-version4+get-5273@lists.php.net to get a copy of this message
After a bit of hacking, AOLserver performs now well. And it does not crash anymore, nor does it lock up. The attached patch to TSRM.c is necessary to allow recursive calls to some tsrm functions. Dropping the lock temporary does not work reliable, and will lead to races. I'd appreciate feedback for this patch. The idea is to "emulate" recursive mutexes. My tests (running http_load with 100 parallel fetches) show that it seems to work. -- Regards, Sascha Schumann Consultant

? difx Index: TSRM.c =================================================================== RCS file: /repository/TSRM/TSRM.c,v retrieving revision 1.8 diff -u -r1.8 TSRM.c --- TSRM.c 1999/09/27 15:37:00 1.8 +++ TSRM.c 1999/10/07 12:00:33 @@ -48,7 +48,7 @@ static tsrm_resource_type *resource_types_table; static int resource_types_table_size; - +static THREAD_T tsmm_owner; static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ /* New thread handlers */ @@ -124,11 +124,17 @@ { ts_rsrc_id new_id; int i; + int update = 0; tsrm_debug("Obtaining a new resource id, %d bytes\n", size); - tsrm_mutex_lock(tsmm_mutex); + if (tsmm_owner != tsrm_thread_id()) { + tsrm_mutex_lock(tsmm_mutex); + tsmm_owner = tsrm_thread_id(); + update = 1; + } + /* obtain a resource id */ new_id = id_count++; tsrm_debug("Obtained resource id %d\n", new_id); @@ -164,8 +170,11 @@ } p = p->next; } + } + if (update == 1) { + tsmm_owner = (THREAD_T) -1; + tsrm_mutex_unlock(tsmm_mutex); } - tsrm_mutex_unlock(tsmm_mutex); tsrm_debug("Successfully allocated new resource id %d\n", new_id); return new_id; @@ -175,7 +184,7 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id) { int i; - + if (tsrm_new_thread_begin_handler) { tsrm_new_thread_begin_handler(thread_id); } @@ -204,9 +213,14 @@ int hash_value; tsrm_tls_entry *thread_resources; void *resource; + int update = 0; tsrm_debug("Fetching resource id %d for thread %ld\n", id, (long) thread_id); - tsrm_mutex_lock(tsmm_mutex); + if (tsmm_owner != tsrm_thread_id()) { + tsrm_mutex_lock(tsmm_mutex); + tsmm_owner = tsrm_thread_id(); + update = 1; + } hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); thread_resources = tsrm_tls_table[hash_value]; @@ -230,9 +244,12 @@ } resource = thread_resources->storage[id]; - - tsrm_mutex_unlock(tsmm_mutex); - + + if (update == 1) { + tsmm_owner = (THREAD_T) -1; + tsrm_mutex_unlock(tsmm_mutex); + } + tsrm_debug("Successfully fetched resource id %d for thread id %ld - %x\n", id, (long) thread_id, (long) resource); return resource; } @@ -247,6 +264,7 @@ tsrm_tls_entry *last=NULL; tsrm_mutex_lock(tsmm_mutex); + tsmm_owner = thread_id; hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); thread_resources = tsrm_tls_table[hash_value]; @@ -274,6 +292,7 @@ } thread_resources = thread_resources->next; } + tsmm_owner = (THREAD_T) -1; tsrm_mutex_unlock(tsmm_mutex); }
« previous php.version4 (#5273) next »