Skip to content

Commit

Permalink
Support for SGI's State Threads. Will be used by PHP's thttpd SAPI
Browse files Browse the repository at this point in the history
initially.
  • Loading branch information
Sascha Schumann committed Jun 21, 2001
1 parent 851b1e3 commit 6ae7e5f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
25 changes: 23 additions & 2 deletions TSRM/TSRM.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ static FILE *tsrm_error_file;
#if defined(PTHREADS) #if defined(PTHREADS)
/* Thread local storage */ /* Thread local storage */
static pthread_key_t tls_key; static pthread_key_t tls_key;
#elif defined(TSRM_ST)
static int tls_key;
#endif #endif




Expand All @@ -85,6 +87,9 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
pth_init(); pth_init();
#elif defined(PTHREADS) #elif defined(PTHREADS)
pthread_key_create( &tls_key, 0 ); pthread_key_create( &tls_key, 0 );
#elif defined(TSRM_ST)
st_init();
st_key_create(&tls_key, 0);
#endif #endif


tsrm_error_file = stderr; tsrm_error_file = stderr;
Expand Down Expand Up @@ -227,6 +232,8 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
#if defined(PTHREADS) #if defined(PTHREADS)
/* Set thread local storage to this new thread resources structure */ /* Set thread local storage to this new thread resources structure */
pthread_setspecific( tls_key, (void *)*thread_resources_ptr ); pthread_setspecific( tls_key, (void *)*thread_resources_ptr );
#elif defined(TSRM_ST)
st_thread_setspecific(tls_key, (void *) *thread_resources_ptr);
#endif #endif


if (tsrm_new_thread_begin_handler) { if (tsrm_new_thread_begin_handler) {
Expand Down Expand Up @@ -262,11 +269,15 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
* and our hashtable lookup. * and our hashtable lookup.
*/ */
thread_resources = pthread_getspecific( tls_key ); thread_resources = pthread_getspecific( tls_key );
#elif defined(TSRM_ST)
thread_resources = st_thread_getspecific(tls_key);
#else
thread_resources = NULL;
#endif
if (thread_resources) { if (thread_resources) {
TSRM_ERROR(TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for current thread %d", id, (long) thread_resources->thread_id ); TSRM_ERROR(TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for current thread %d", id, (long) thread_resources->thread_id );
return ts_resource_read( thread_resources, id ); return ts_resource_read( thread_resources, id );
} }
#endif
thread_id = tsrm_thread_id(); thread_id = tsrm_thread_id();
} else { } else {
thread_id = *th_id; thread_id = *th_id;
Expand Down Expand Up @@ -391,6 +402,8 @@ TSRM_API THREAD_T tsrm_thread_id(void)
return systhread_current(); return systhread_current();
#elif defined(PI3WEB) #elif defined(PI3WEB)
return PIThread_getCurrent(); return PIThread_getCurrent();
#elif defined(TSRM_ST)
return st_thread_self();
#endif #endif
} }


Expand All @@ -413,6 +426,8 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
mutexp = crit_init(); mutexp = crit_init();
#elif defined(PI3WEB) #elif defined(PI3WEB)
mutexp = PIPlatform_allocLocalMutex(); mutexp = PIPlatform_allocLocalMutex();
#elif defined(TSRM_ST)
mutexp = st_mutex_new();
#endif #endif
#ifdef THR_DEBUG #ifdef THR_DEBUG
printf("Mutex created thread: %d\n",mythreadid()); printf("Mutex created thread: %d\n",mythreadid());
Expand All @@ -435,7 +450,9 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
#elif defined(NSAPI) #elif defined(NSAPI)
crit_terminate(mutexp); crit_terminate(mutexp);
#elif defined(PI3WEB) #elif defined(PI3WEB)
PISync_delete(mutexp) PISync_delete(mutexp);
#elif defined(TSRM_ST)
st_mutex_destroy(mutexp);
#endif #endif
} }
#ifdef THR_DEBUG #ifdef THR_DEBUG
Expand All @@ -459,6 +476,8 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
return crit_enter(mutexp); return crit_enter(mutexp);
#elif defined(PI3WEB) #elif defined(PI3WEB)
return PISync_lock(mutexp); return PISync_lock(mutexp);
#elif defined(TSRM_ST)
return st_mutex_lock(mutexp);
#endif #endif
} }


Expand All @@ -478,6 +497,8 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
return crit_exit(mutexp); return crit_exit(mutexp);
#elif defined(PI3WEB) #elif defined(PI3WEB)
return PISync_unlock(mutexp); return PISync_unlock(mutexp);
#elif defined(TSRM_ST)
return st_mutex_unlock(mutexp);
#endif #endif
} }


Expand Down
5 changes: 5 additions & 0 deletions TSRM/TSRM.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# include <pth.h> # include <pth.h>
#elif defined(PTHREADS) #elif defined(PTHREADS)
# include <pthread.h> # include <pthread.h>
#elif defined(TSRM_ST)
# include <st.h>
#endif #endif


typedef int ts_rsrc_id; typedef int ts_rsrc_id;
Expand Down Expand Up @@ -61,6 +63,9 @@ typedef int ts_rsrc_id;
#elif defined(PI3WEB) #elif defined(PI3WEB)
# define THREAD_T PIThread * # define THREAD_T PIThread *
# define MUTEX_T PISync * # define MUTEX_T PISync *
#elif defined(TSRM_ST)
# define THREAD_T st_thread_t
# define MUTEX_T st_mutex_t
#endif #endif


typedef void (*ts_allocate_ctor)(void *); typedef void (*ts_allocate_ctor)(void *);
Expand Down
26 changes: 26 additions & 0 deletions TSRM/tsrm.m4
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ AC_MSG_RESULT(yes - installed in $PTH_PREFIX)
]) ])


AC_DEFUN(TSRM_CHECK_ST,[
if test -r "$1/include/st.h"; then
CPPFLAGS="$CPPFLAGS -I$1/include"
LDFLAGS="$LDFLAGS -L$1/lib"
elif test -r "$1/st.h"; then
CPPFLAGS="$CPPFLAGS -I$1"
LDFLAGS="$LDFLAGS -L$1"
fi
AC_CHECK_HEADERS(st.h,[ ],[
AC_MSG_ERROR([Sorry[,] I was unable to locate the State Threads header file. Please specify the prefix using --with-tsrm-st=/prefix])
])
LIBS="$LIBS -lst"
AC_MSG_CHECKING(for SGI's State Threads)
AC_MSG_RESULT(yes)
AC_DEFINE(TSRM_ST, 1, [ ])
])

sinclude(threads.m4) sinclude(threads.m4)
sinclude(TSRM/threads.m4) sinclude(TSRM/threads.m4)


Expand Down Expand Up @@ -80,6 +97,13 @@ AC_ARG_WITH(tsrm-pth,
TSRM_PTH=no TSRM_PTH=no
]) ])
AC_ARG_WITH(tsrm-st,
[ --with-tsrm-st],[
TSRM_ST=$withval
],[
TSRM_ST=no
])
AC_ARG_WITH(tsrm-pthreads, AC_ARG_WITH(tsrm-pthreads,
[ --with-tsrm-pthreads Use POSIX threads (default)],[ [ --with-tsrm-pthreads Use POSIX threads (default)],[
TSRM_PTHREADS=$withval TSRM_PTHREADS=$withval
Expand All @@ -91,6 +115,8 @@ test "$TSRM_PTH" = "yes" && TSRM_PTH=pth-config
if test "$TSRM_PTH" != "no"; then if test "$TSRM_PTH" != "no"; then
TSRM_CHECK_PTH($TSRM_PTH) TSRM_CHECK_PTH($TSRM_PTH)
elif test "$TSRM_ST" != "no"; then
TSRM_CHECK_ST($TSRM_ST)
elif test "$TSRM_PTHREADS" != "no"; then elif test "$TSRM_PTHREADS" != "no"; then
TSRM_CHECK_PTHREADS TSRM_CHECK_PTHREADS
fi fi
Expand Down

0 comments on commit 6ae7e5f

Please sign in to comment.