dreid Sat Oct 5 07:26:17 2002 EDT Modified files: /TSRM TSRM.c TSRM.h threads.m4 tsrm.m4 tsrm_virtual_cwd.c Log: 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. Index: TSRM/TSRM.c diff -u TSRM/TSRM.c:1.44 TSRM/TSRM.c:1.45 --- TSRM/TSRM.c:1.44 Wed Aug 7 10:47:05 2002 +++ TSRM/TSRM.c Sat Oct 5 07:26:17 2002 @@ -95,9 +95,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ return PIThread_getCurrent(); #elif defined(TSRM_ST) return st_thread_self(); +#elif defined(BETHREADS) + return find_thread(NULL); #endif } @@ -454,6 +463,10 @@ 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 @@ 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 @@ 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 @@ 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 } Index: TSRM/TSRM.h diff -u TSRM/TSRM.h:1.35 TSRM/TSRM.h:1.36 --- TSRM/TSRM.h:1.35 Wed Aug 7 10:47:05 2002 +++ TSRM/TSRM.h Sat Oct 5 07:26:17 2002 @@ -47,6 +47,9 @@ # include <pthread.h> #elif defined(TSRM_ST) # include <st.h> +#elif defined(BETHREADS) +#include <kernel/OS.h> +#include <TLS.h> #endif typedef int ts_rsrc_id; @@ -73,6 +76,13 @@ #elif defined(TSRM_ST) # define THREAD_T st_thread_t # define MUTEX_T st_mutex_t +#elif defined(BETHREADS) +# define THREAD_T thread_id +typedef struct { + sem_id sem; + int32 ben; +} beos_ben; +# define MUTEX_T beos_ben * #endif typedef void (*ts_allocate_ctor)(void *, void ***); Index: TSRM/threads.m4 diff -u TSRM/threads.m4:1.11 TSRM/threads.m4:1.12 --- TSRM/threads.m4:1.11 Wed Sep 19 05:01:05 2001 +++ TSRM/threads.m4 Sat Oct 5 07:26:17 2002 @@ -102,26 +102,31 @@ dnl AC_DEFUN(PTHREADS_CHECK,[ -save_CFLAGS=$CFLAGS -save_LIBS=$LIBS -PTHREADS_ASSIGN_VARS -PTHREADS_CHECK_COMPILE -LIBS=$save_LIBS -CFLAGS=$save_CFLAGS +if test "$beos_threads" = "1"; then + pthreads_working="yes" + ac_cv_pthreads_cflags="" +else + save_CFLAGS=$CFLAGS + save_LIBS=$LIBS + PTHREADS_ASSIGN_VARS + PTHREADS_CHECK_COMPILE + LIBS=$save_LIBS + CFLAGS=$save_CFLAGS -AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[ -ac_cv_pthreads_cflags= -if test "$pthreads_working" != "yes"; then - for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do - ac_save=$CFLAGS - CFLAGS="$CFLAGS $flag" - PTHREADS_CHECK_COMPILE - CFLAGS=$ac_save - if test "$pthreads_working" = "yes"; then - ac_cv_pthreads_cflags=$flag - break - fi - done + AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[ + ac_cv_pthreads_cflags= + if test "$pthreads_working" != "yes"; then + for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt +-qthreaded; do + ac_save=$CFLAGS + CFLAGS="$CFLAGS $flag" + PTHREADS_CHECK_COMPILE + CFLAGS=$ac_save + if test "$pthreads_working" = "yes"; then + ac_cv_pthreads_cflags=$flag + break + fi + done + fi fi ]) Index: TSRM/tsrm.m4 diff -u TSRM/tsrm.m4:1.13 TSRM/tsrm.m4:1.14 --- TSRM/tsrm.m4:1.13 Tue Aug 21 07:00:22 2001 +++ TSRM/tsrm.m4 Sat Oct 5 07:26:17 2002 @@ -73,15 +73,19 @@ AC_DEFUN(TSRM_CHECK_PTHREADS,[ PTHREADS_CHECK - -if test "$pthreads_working" != "yes"; then - AC_MSG_ERROR(Your system seems to lack POSIX threads.) -fi - -AC_DEFINE(PTHREADS, 1, Whether to use Pthreads) -AC_MSG_CHECKING(for POSIX threads) -AC_MSG_RESULT(yes) +if test "$beos_threads" = "1"; then + AC_DEFINE(BETHREADS, 1, Whether to use native BeOS threads) +else + if test "$pthreads_working" != "yes"; then + AC_MSG_ERROR(Your system seems to lack POSIX threads.) + fi + + AC_DEFINE(PTHREADS, 1, Whether to use Pthreads) + + AC_MSG_CHECKING(for POSIX threads) + AC_MSG_RESULT(yes) +fi ]) Index: TSRM/tsrm_virtual_cwd.c diff -u TSRM/tsrm_virtual_cwd.c:1.31 TSRM/tsrm_virtual_cwd.c:1.32 --- TSRM/tsrm_virtual_cwd.c:1.31 Thu Oct 3 21:04:00 2002 +++ TSRM/tsrm_virtual_cwd.c Sat Oct 5 07:26:17 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.c,v 1.31 2002/10/04 01:04:00 sas Exp $ */ +/* $Id: tsrm_virtual_cwd.c,v 1.32 2002/10/05 11:26:17 dreid Exp $ */ #include <sys/types.h> #include <sys/stat.h> @@ -41,6 +41,10 @@ #include "tsrm_nw.h" #endif +#ifdef __BEOS__ +#define realpath(x,y) strcpy(y,x) +#endif + #define VIRTUAL_CWD_DEBUG 0 #include "TSRM.h" @@ -298,7 +302,7 @@ if (path_length == 0) return (0); -#if !defined(TSRM_WIN32) && !defined(__BEOS__) && !defined(NETWARE) +#if !defined(TSRM_WIN32) && !defined(NETWARE) if (IS_ABSOLUTE_PATH(path, path_length)) { if (realpath(path, resolved_path)) { path = resolved_path;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php