Skip to content

Commit 2a0fbde

Browse files
author
David Reid
committed
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.
1 parent 4ca381a commit 2a0fbde

File tree

5 files changed

+76
-29
lines changed

5 files changed

+76
-29
lines changed

TSRM/TSRM.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ static pthread_key_t tls_key;
9595
static int tls_key;
9696
#elif defined(TSRM_WIN32)
9797
static DWORD tls_key;
98+
#elif defined(BETHREADS)
99+
static int32 tls_key;
98100
#endif
99101

100-
101102
/* Startup TSRM (call once for the entire process) */
102103
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
103104
{
@@ -110,6 +111,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
110111
st_key_create(&tls_key, 0);
111112
#elif defined(TSRM_WIN32)
112113
tls_key = TlsAlloc();
114+
#elif defined(BETHREADS)
115+
tls_key = tls_allocate();
113116
#endif
114117

115118
tsrm_error_file = stderr;
@@ -258,6 +261,8 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
258261
st_thread_setspecific(tls_key, (void *) *thread_resources_ptr);
259262
#elif defined(TSRM_WIN32)
260263
TlsSetValue(tls_key, (void *) *thread_resources_ptr);
264+
#elif defined(BETHREADS)
265+
tls_set(tls_key, (void*) *thread_resources_ptr);
261266
#endif
262267

263268
if (tsrm_new_thread_begin_handler) {
@@ -297,6 +302,8 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
297302
thread_resources = st_thread_getspecific(tls_key);
298303
#elif defined(TSRM_WIN32)
299304
thread_resources = TlsGetValue(tls_key);
305+
#elif defined(BETHREADS)
306+
thread_resources = (tsrm_tls_entry*)tls_get(tls_key);
300307
#else
301308
thread_resources = NULL;
302309
#endif
@@ -423,6 +430,8 @@ TSRM_API THREAD_T tsrm_thread_id(void)
423430
return PIThread_getCurrent();
424431
#elif defined(TSRM_ST)
425432
return st_thread_self();
433+
#elif defined(BETHREADS)
434+
return find_thread(NULL);
426435
#endif
427436
}
428437

@@ -454,6 +463,10 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
454463
mutexp = PIPlatform_allocLocalMutex();
455464
#elif defined(TSRM_ST)
456465
mutexp = st_mutex_new();
466+
#elif defined(BETHREADS)
467+
mutexp = (beos_ben*)malloc(sizeof(beos_ben));
468+
mutexp->ben = 0;
469+
mutexp->sem = create_sem(1, "PHP sempahore");
457470
#endif
458471
#ifdef THR_DEBUG
459472
printf("Mutex created thread: %d\n",mythreadid());
@@ -481,6 +494,9 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
481494
PISync_delete(mutexp);
482495
#elif defined(TSRM_ST)
483496
st_mutex_destroy(mutexp);
497+
#elif defined(BETHREADS)
498+
delete_sem(mutexp->sem);
499+
free(mutexp);
484500
#endif
485501
}
486502
#ifdef THR_DEBUG
@@ -508,6 +524,10 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
508524
return PISync_lock(mutexp);
509525
#elif defined(TSRM_ST)
510526
return st_mutex_lock(mutexp);
527+
#elif defined(BETHREADS)
528+
if (atomic_add(&mutexp->ben, 1) != 0)
529+
return acquire_sem(mutexp->sem);
530+
return 0;
511531
#endif
512532
}
513533

@@ -531,6 +551,10 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
531551
return PISync_unlock(mutexp);
532552
#elif defined(TSRM_ST)
533553
return st_mutex_unlock(mutexp);
554+
#elif defined(BETHREADS)
555+
if (atomic_add(&mutexp->ben, -1) != 1)
556+
return release_sem(mutexp->sem);
557+
return 0;
534558
#endif
535559
}
536560

TSRM/TSRM.h

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
# include <pthread.h>
4848
#elif defined(TSRM_ST)
4949
# include <st.h>
50+
#elif defined(BETHREADS)
51+
#include <kernel/OS.h>
52+
#include <TLS.h>
5053
#endif
5154

5255
typedef int ts_rsrc_id;
@@ -73,6 +76,13 @@ typedef int ts_rsrc_id;
7376
#elif defined(TSRM_ST)
7477
# define THREAD_T st_thread_t
7578
# define MUTEX_T st_mutex_t
79+
#elif defined(BETHREADS)
80+
# define THREAD_T thread_id
81+
typedef struct {
82+
sem_id sem;
83+
int32 ben;
84+
} beos_ben;
85+
# define MUTEX_T beos_ben *
7686
#endif
7787

7888
typedef void (*ts_allocate_ctor)(void *, void ***);

TSRM/threads.m4

+24-19
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,31 @@ dnl -threads gcc (HP-UX)
102102
dnl
103103
AC_DEFUN(PTHREADS_CHECK,[
104104
105-
save_CFLAGS=$CFLAGS
106-
save_LIBS=$LIBS
107-
PTHREADS_ASSIGN_VARS
108-
PTHREADS_CHECK_COMPILE
109-
LIBS=$save_LIBS
110-
CFLAGS=$save_CFLAGS
105+
if test "$beos_threads" = "1"; then
106+
pthreads_working="yes"
107+
ac_cv_pthreads_cflags=""
108+
else
109+
save_CFLAGS=$CFLAGS
110+
save_LIBS=$LIBS
111+
PTHREADS_ASSIGN_VARS
112+
PTHREADS_CHECK_COMPILE
113+
LIBS=$save_LIBS
114+
CFLAGS=$save_CFLAGS
111115
112-
AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
113-
ac_cv_pthreads_cflags=
114-
if test "$pthreads_working" != "yes"; then
115-
for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
116-
ac_save=$CFLAGS
117-
CFLAGS="$CFLAGS $flag"
118-
PTHREADS_CHECK_COMPILE
119-
CFLAGS=$ac_save
120-
if test "$pthreads_working" = "yes"; then
121-
ac_cv_pthreads_cflags=$flag
122-
break
123-
fi
124-
done
116+
AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
117+
ac_cv_pthreads_cflags=
118+
if test "$pthreads_working" != "yes"; then
119+
for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
120+
ac_save=$CFLAGS
121+
CFLAGS="$CFLAGS $flag"
122+
PTHREADS_CHECK_COMPILE
123+
CFLAGS=$ac_save
124+
if test "$pthreads_working" = "yes"; then
125+
ac_cv_pthreads_cflags=$flag
126+
break
127+
fi
128+
done
129+
fi
125130
fi
126131
])
127132

TSRM/tsrm.m4

+12-8
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ sinclude(TSRM/threads.m4)
7373
AC_DEFUN(TSRM_CHECK_PTHREADS,[
7474
7575
PTHREADS_CHECK
76-
77-
if test "$pthreads_working" != "yes"; then
78-
AC_MSG_ERROR(Your system seems to lack POSIX threads.)
79-
fi
80-
81-
AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)
8276
83-
AC_MSG_CHECKING(for POSIX threads)
84-
AC_MSG_RESULT(yes)
77+
if test "$beos_threads" = "1"; then
78+
AC_DEFINE(BETHREADS, 1, Whether to use native BeOS threads)
79+
else
80+
if test "$pthreads_working" != "yes"; then
81+
AC_MSG_ERROR(Your system seems to lack POSIX threads.)
82+
fi
83+
84+
AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)
85+
86+
AC_MSG_CHECKING(for POSIX threads)
87+
AC_MSG_RESULT(yes)
88+
fi
8589
])
8690

8791

TSRM/tsrm_virtual_cwd.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include "tsrm_nw.h"
4242
#endif
4343

44+
#ifdef __BEOS__
45+
#define realpath(x,y) strcpy(y,x)
46+
#endif
47+
4448
#define VIRTUAL_CWD_DEBUG 0
4549

4650
#include "TSRM.h"
@@ -298,7 +302,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
298302
if (path_length == 0)
299303
return (0);
300304

301-
#if !defined(TSRM_WIN32) && !defined(__BEOS__) && !defined(NETWARE)
305+
#if !defined(TSRM_WIN32) && !defined(NETWARE)
302306
if (IS_ABSOLUTE_PATH(path, path_length)) {
303307
if (realpath(path, resolved_path)) {
304308
path = resolved_path;

0 commit comments

Comments
 (0)