diff options
author | David Reid <dreid@php.net> | 2002-10-05 11:26:17 +0000 |
---|---|---|
committer | David Reid <dreid@php.net> | 2002-10-05 11:26:17 +0000 |
commit | 2a0fbded3dc3f366cf3e4bfd3a42c7a2f5d2b745 (patch) | |
tree | 16a454a99aa47c8b954271b995bd200712af8326 /TSRM/TSRM.c | |
parent | 4ca381aacfc77f43d02895d7ced4ecd36b5a286e (diff) | |
download | php-git-2a0fbded3dc3f366cf3e4bfd3a42c7a2f5d2b745.tar.gz |
Add BeOS thread support to TSRM. This should not impact on any other OS's
but allows us to build PHP with threading support and therefore we can
build as an Apache 2 module.
The locking is currently done using benaphores but this may be reviewed.
Diffstat (limited to 'TSRM/TSRM.c')
-rw-r--r-- | TSRM/TSRM.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index f391a8c40b..2f50307aa4 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -95,9 +95,10 @@ static pthread_key_t tls_key; static int tls_key; #elif defined(TSRM_WIN32) static DWORD tls_key; +#elif defined(BETHREADS) +static int32 tls_key; #endif - /* Startup TSRM (call once for the entire process) */ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename) { @@ -110,6 +111,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu st_key_create(&tls_key, 0); #elif defined(TSRM_WIN32) tls_key = TlsAlloc(); +#elif defined(BETHREADS) + tls_key = tls_allocate(); #endif tsrm_error_file = stderr; @@ -258,6 +261,8 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_ st_thread_setspecific(tls_key, (void *) *thread_resources_ptr); #elif defined(TSRM_WIN32) TlsSetValue(tls_key, (void *) *thread_resources_ptr); +#elif defined(BETHREADS) + tls_set(tls_key, (void*) *thread_resources_ptr); #endif if (tsrm_new_thread_begin_handler) { @@ -297,6 +302,8 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id) thread_resources = st_thread_getspecific(tls_key); #elif defined(TSRM_WIN32) thread_resources = TlsGetValue(tls_key); +#elif defined(BETHREADS) + thread_resources = (tsrm_tls_entry*)tls_get(tls_key); #else thread_resources = NULL; #endif @@ -423,6 +430,8 @@ TSRM_API THREAD_T tsrm_thread_id(void) return PIThread_getCurrent(); #elif defined(TSRM_ST) return st_thread_self(); +#elif defined(BETHREADS) + return find_thread(NULL); #endif } @@ -454,6 +463,10 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void) mutexp = PIPlatform_allocLocalMutex(); #elif defined(TSRM_ST) mutexp = st_mutex_new(); +#elif defined(BETHREADS) + mutexp = (beos_ben*)malloc(sizeof(beos_ben)); + mutexp->ben = 0; + mutexp->sem = create_sem(1, "PHP sempahore"); #endif #ifdef THR_DEBUG printf("Mutex created thread: %d\n",mythreadid()); @@ -481,6 +494,9 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp) PISync_delete(mutexp); #elif defined(TSRM_ST) st_mutex_destroy(mutexp); +#elif defined(BETHREADS) + delete_sem(mutexp->sem); + free(mutexp); #endif } #ifdef THR_DEBUG @@ -508,6 +524,10 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp) return PISync_lock(mutexp); #elif defined(TSRM_ST) return st_mutex_lock(mutexp); +#elif defined(BETHREADS) + if (atomic_add(&mutexp->ben, 1) != 0) + return acquire_sem(mutexp->sem); + return 0; #endif } @@ -531,6 +551,10 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp) return PISync_unlock(mutexp); #elif defined(TSRM_ST) return st_mutex_unlock(mutexp); +#elif defined(BETHREADS) + if (atomic_add(&mutexp->ben, -1) != 1) + return release_sem(mutexp->sem); + return 0; #endif } |