summaryrefslogtreecommitdiff
path: root/TSRM/TSRM.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-07-04 17:06:52 +0200
committerAnatol Belski <ab@php.net>2017-07-04 17:06:52 +0200
commit6a3a2bf18eceba346aa0857c9bfba0c5525fdb3b (patch)
tree3be6e6e65404aa5bf1bf017a5646d2bc723fd21d /TSRM/TSRM.c
parenta0203ea14318c0009efcf99d9735ada783a02d14 (diff)
downloadphp-git-6a3a2bf18eceba346aa0857c9bfba0c5525fdb3b.tar.gz
vim folds and mode lines yet
Diffstat (limited to 'TSRM/TSRM.c')
-rw-r--r--TSRM/TSRM.c105
1 files changed, 57 insertions, 48 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c
index 4c635a05a9..cde8437790 100644
--- a/TSRM/TSRM.c
+++ b/TSRM/TSRM.c
@@ -125,7 +125,7 @@ TSRM_TLS uint8_t in_main_thread = 0;
/* 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)
-{
+{/*{{{*/
#if defined(GNUPTH)
pth_init();
#elif defined(PTHREADS)
@@ -166,12 +166,12 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources));
return 1;
-}
+}/*}}}*/
/* Shutdown TSRM (call once for the entire process) */
TSRM_API void tsrm_shutdown(void)
-{
+{/*{{{*/
int i;
if (!in_main_thread) {
@@ -227,12 +227,12 @@ TSRM_API void tsrm_shutdown(void)
tsrm_new_thread_begin_handler = NULL;
tsrm_new_thread_end_handler = NULL;
tsrm_shutdown_handler = NULL;
-}
+}/*}}}*/
/* allocates a new thread-safe-resource id */
TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
-{
+{/*{{{*/
int i;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
@@ -283,11 +283,11 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
return *rsrc_id;
-}
+}/*}}}*/
static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id)
-{
+{/*{{{*/
int i;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
@@ -323,12 +323,12 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* fetches the requested resource for the current thread */
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
-{
+{/*{{{*/
THREAD_T thread_id;
int hash_value;
tsrm_tls_entry *thread_resources;
@@ -386,12 +386,12 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
* changes to the structure as we read it.
*/
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
-}
+}/*}}}*/
/* frees an interpreter context. You are responsible for making sure that
* it is not linked into the TSRM hash, and not marked as the current interpreter */
void tsrm_free_interpreter_context(void *context)
-{
+{/*{{{*/
tsrm_tls_entry *next, *thread_resources = (tsrm_tls_entry*)context;
int i;
@@ -410,10 +410,10 @@ void tsrm_free_interpreter_context(void *context)
free(thread_resources);
thread_resources = next;
}
-}
+}/*}}}*/
void *tsrm_set_interpreter_context(void *new_ctx)
-{
+{/*{{{*/
tsrm_tls_entry *current;
current = tsrm_tls_get();
@@ -426,12 +426,12 @@ void *tsrm_set_interpreter_context(void *new_ctx)
/* return old context, so caller can restore it when they're done */
return current;
-}
+}/*}}}*/
/* allocates a new interpreter context */
void *tsrm_new_interpreter_context(void)
-{
+{/*{{{*/
tsrm_tls_entry *new_ctx, *current;
THREAD_T thread_id;
@@ -445,12 +445,12 @@ void *tsrm_new_interpreter_context(void)
/* switch back to the context that was in use prior to our creation
* of the new one */
return tsrm_set_interpreter_context(current);
-}
+}/*}}}*/
/* frees all resources allocated for the current thread */
void ts_free_thread(void)
-{
+{/*{{{*/
tsrm_tls_entry *thread_resources;
int i;
THREAD_T thread_id = tsrm_thread_id();
@@ -487,12 +487,12 @@ void ts_free_thread(void)
thread_resources = thread_resources->next;
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* frees all resources allocated for all threads except current */
void ts_free_worker_threads(void)
-{
+{/*{{{*/
tsrm_tls_entry *thread_resources;
int i;
THREAD_T thread_id = tsrm_thread_id();
@@ -533,12 +533,12 @@ void ts_free_worker_threads(void)
}
}
tsrm_mutex_unlock(tsmm_mutex);
-}
+}/*}}}*/
/* deallocates all occurrences of a given id */
void ts_free_id(ts_rsrc_id id)
-{
+{/*{{{*/
int i;
int j = TSRM_UNSHUFFLE_RSRC_ID(id);
@@ -567,7 +567,7 @@ void ts_free_id(ts_rsrc_id id)
tsrm_mutex_unlock(tsmm_mutex);
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id));
-}
+}/*}}}*/
@@ -578,7 +578,7 @@ void ts_free_id(ts_rsrc_id id)
/* Obtain the current thread id */
TSRM_API THREAD_T tsrm_thread_id(void)
-{
+{/*{{{*/
#ifdef TSRM_WIN32
return GetCurrentThreadId();
#elif defined(GNUPTH)
@@ -594,12 +594,12 @@ TSRM_API THREAD_T tsrm_thread_id(void)
#elif defined(BETHREADS)
return find_thread(NULL);
#endif
-}
+}/*}}}*/
/* Allocate a mutex */
TSRM_API MUTEX_T tsrm_mutex_alloc(void)
-{
+{/*{{{*/
MUTEX_T mutexp;
#ifdef TSRM_WIN32
mutexp = malloc(sizeof(CRITICAL_SECTION));
@@ -625,12 +625,12 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
printf("Mutex created thread: %d\n",mythreadid());
#endif
return( mutexp );
-}
+}/*}}}*/
/* Free a mutex */
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
-{
+{/*{{{*/
if (mutexp) {
#ifdef TSRM_WIN32
DeleteCriticalSection(mutexp);
@@ -654,7 +654,7 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
#ifdef THR_DEBUG
printf("Mutex freed thread: %d\n",mythreadid());
#endif
-}
+}/*}}}*/
/*
@@ -662,7 +662,7 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
EnterCriticalSection(mutexp);
@@ -686,7 +686,7 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
return acquire_sem(mutexp->sem);
return 0;
#endif
-}
+}/*}}}*/
/*
@@ -694,7 +694,7 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
LeaveCriticalSection(mutexp);
@@ -718,14 +718,14 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
return release_sem(mutexp->sem);
return 0;
#endif
-}
+}/*}}}*/
/*
Changes the signal mask of the calling thread
*/
#ifdef HAVE_SIGPROCMASK
TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset)
-{
+{/*{{{*/
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Changed sigmask in thread: %ld", tsrm_thread_id()));
/* TODO: add support for other APIs */
#ifdef PTHREADS
@@ -733,35 +733,35 @@ TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset)
#else
return sigprocmask(how, set, oldset);
#endif
-}
+}/*}}}*/
#endif
TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler)
-{
+{/*{{{*/
void *retval = (void *) tsrm_new_thread_begin_handler;
tsrm_new_thread_begin_handler = new_thread_begin_handler;
return retval;
-}
+}/*}}}*/
TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler)
-{
+{/*{{{*/
void *retval = (void *) tsrm_new_thread_end_handler;
tsrm_new_thread_end_handler = new_thread_end_handler;
return retval;
-}
+}/*}}}*/
TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
-{
+{/*{{{*/
void *retval = (void *) tsrm_shutdown_handler;
tsrm_shutdown_handler = shutdown_handler;
return retval;
-}
+}/*}}}*/
/*
@@ -770,7 +770,7 @@ TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
#if TSRM_DEBUG
int tsrm_error(int level, const char *format, ...)
-{
+{/*{{{*/
if (level<=tsrm_error_level) {
va_list args;
int size;
@@ -785,12 +785,12 @@ int tsrm_error(int level, const char *format, ...)
} else {
return 0;
}
-}
+}/*}}}*/
#endif
void tsrm_error_set(int level, char *debug_filename)
-{
+{/*{{{*/
tsrm_error_level = level;
#if TSRM_DEBUG
@@ -807,16 +807,25 @@ void tsrm_error_set(int level, char *debug_filename)
tsrm_error_file = stderr;
}
#endif
-}
+}/*}}}*/
TSRM_API void *tsrm_get_ls_cache(void)
-{
+{/*{{{*/
return tsrm_tls_get();
-}
+}/*}}}*/
TSRM_API uint8_t tsrm_is_main_thread(void)
-{
+{/*{{{*/
return in_main_thread;
-}
+}/*}}}*/
#endif /* ZTS */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */