1999-04-23 19:00:02 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Thread Safe Resource Manager |
|
|
|
|
+----------------------------------------------------------------------+
|
2011-01-01 10:17:06 +08:00
|
|
|
| Copyright (c) 1999-2011, Andi Gutmans, Sascha Schumann, Zeev Suraski |
|
2000-09-01 03:02:14 +08:00
|
|
|
| This source file is subject to the TSRM license, that is bundled |
|
|
|
|
| with this package in the file LICENSE |
|
1999-04-23 19:00:02 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2018-11-02 00:30:28 +08:00
|
|
|
| Authors: Zeev Suraski <zeev@php.net> |
|
1999-04-23 19:00:02 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
#include "TSRM.h"
|
2000-09-01 07:44:10 +08:00
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
#include <stdio.h>
|
1999-04-24 17:01:30 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
#ifdef ZEND_DEBUG
|
|
|
|
# include <assert.h>
|
|
|
|
# define TSRM_ASSERT assert
|
|
|
|
#else
|
|
|
|
# define TSRM_ASSERT
|
|
|
|
#endif
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
typedef struct _tsrm_tls_entry tsrm_tls_entry;
|
|
|
|
|
2014-10-15 22:33:40 +08:00
|
|
|
/* TSRMLS_CACHE_DEFINE; is already done in Zend, this is being always compiled statically. */
|
2019-03-12 22:35:50 +08:00
|
|
|
TSRMLS_CACHE_EXTERN();
|
2014-10-15 22:33:40 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
struct _tsrm_tls_entry {
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
void **storage;
|
1999-04-21 07:58:02 +08:00
|
|
|
int count;
|
|
|
|
THREAD_T thread_id;
|
|
|
|
tsrm_tls_entry *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t size;
|
1999-12-06 00:21:37 +08:00
|
|
|
ts_allocate_ctor ctor;
|
|
|
|
ts_allocate_dtor dtor;
|
2019-03-14 08:01:01 +08:00
|
|
|
size_t fast_offset;
|
2004-05-13 06:28:28 +08:00
|
|
|
int done;
|
1999-04-21 07:58:02 +08:00
|
|
|
} tsrm_resource_type;
|
|
|
|
|
|
|
|
|
|
|
|
/* The memory manager table */
|
2000-11-18 07:31:15 +08:00
|
|
|
static tsrm_tls_entry **tsrm_tls_table=NULL;
|
1999-04-21 07:58:02 +08:00
|
|
|
static int tsrm_tls_table_size;
|
|
|
|
static ts_rsrc_id id_count;
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
/* The resource sizes table */
|
2000-11-18 07:31:15 +08:00
|
|
|
static tsrm_resource_type *resource_types_table=NULL;
|
1999-04-21 07:58:02 +08:00
|
|
|
static int resource_types_table_size;
|
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
/* Reserved space for fast globals access */
|
|
|
|
static size_t tsrm_reserved_pos = 0;
|
|
|
|
static size_t tsrm_reserved_size = 0;
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-29 15:01:31 +08:00
|
|
|
static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */
|
|
|
|
static MUTEX_T tsrm_env_mutex; /* tsrm environ mutex */
|
1999-04-21 07:58:02 +08:00
|
|
|
|
1999-08-14 17:35:52 +08:00
|
|
|
/* New thread handlers */
|
2017-03-04 17:39:13 +08:00
|
|
|
static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler = NULL;
|
|
|
|
static tsrm_thread_end_func_t tsrm_new_thread_end_handler = NULL;
|
|
|
|
static tsrm_shutdown_func_t tsrm_shutdown_handler = NULL;
|
1999-08-14 17:35:52 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
/* Debug support */
|
2000-11-18 10:41:14 +08:00
|
|
|
int tsrm_error(int level, const char *format, ...);
|
2001-03-06 23:07:57 +08:00
|
|
|
|
|
|
|
/* Read a resource from a thread's resource storage */
|
2000-11-18 07:31:15 +08:00
|
|
|
static int tsrm_error_level;
|
2000-11-18 10:41:14 +08:00
|
|
|
static FILE *tsrm_error_file;
|
2001-07-27 18:08:26 +08:00
|
|
|
|
2000-11-18 10:41:14 +08:00
|
|
|
#if TSRM_DEBUG
|
2001-07-27 18:08:26 +08:00
|
|
|
#define TSRM_ERROR(args) tsrm_error args
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
|
2001-07-27 18:08:26 +08:00
|
|
|
{ \
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
int unshuffled_offset = TSRM_UNSHUFFLE_RSRC_ID(offset); \
|
2001-07-27 18:08:26 +08:00
|
|
|
\
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
if (offset==0) { \
|
|
|
|
return &array; \
|
|
|
|
} else if ((unshuffled_offset)>=0 && (unshuffled_offset)<(range)) { \
|
2001-07-27 18:08:26 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Successfully fetched resource id %d for thread id %ld - 0x%0.8X", \
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
unshuffled_offset, (long) thread_resources->thread_id, array[unshuffled_offset])); \
|
|
|
|
return array[unshuffled_offset]; \
|
2001-07-27 18:08:26 +08:00
|
|
|
} else { \
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Resource id %d is out of range (%d..%d)", \
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
unshuffled_offset, TSRM_SHUFFLE_RSRC_ID(0), TSRM_SHUFFLE_RSRC_ID(thread_resources->count-1))); \
|
2001-07-27 18:08:26 +08:00
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
}
|
2000-11-18 07:31:15 +08:00
|
|
|
#else
|
2002-11-06 01:34:47 +08:00
|
|
|
#define TSRM_ERROR(args)
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
|
|
|
|
if (offset==0) { \
|
|
|
|
return &array; \
|
|
|
|
} else { \
|
|
|
|
return array[TSRM_UNSHUFFLE_RSRC_ID(offset)]; \
|
2001-07-27 19:03:32 +08:00
|
|
|
}
|
2000-11-18 07:31:15 +08:00
|
|
|
#endif
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-23 15:15:53 +08:00
|
|
|
#if defined(TSRM_WIN32)
|
2001-07-30 13:46:31 +08:00
|
|
|
static DWORD tls_key;
|
2005-04-28 10:55:14 +08:00
|
|
|
# define tsrm_tls_set(what) TlsSetValue(tls_key, (void*)(what))
|
|
|
|
# define tsrm_tls_get() TlsGetValue(tls_key)
|
|
|
|
#else
|
2019-03-23 15:15:53 +08:00
|
|
|
static pthread_key_t tls_key;
|
|
|
|
# define tsrm_tls_set(what) pthread_setspecific(tls_key, (void*)(what))
|
|
|
|
# define tsrm_tls_get() pthread_getspecific(tls_key)
|
2001-03-06 23:07:57 +08:00
|
|
|
#endif
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
TSRM_TLS uint8_t in_main_thread = 0;
|
2019-06-26 19:18:50 +08:00
|
|
|
TSRM_TLS uint8_t is_thread_shutdown = 0;
|
2017-03-04 17:39:13 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
/* Startup TSRM (call once for the entire process) */
|
2000-11-18 10:41:14 +08:00
|
|
|
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2019-03-23 15:15:53 +08:00
|
|
|
#if defined(TSRM_WIN32)
|
2001-07-30 13:46:31 +08:00
|
|
|
tls_key = TlsAlloc();
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
|
|
|
pthread_key_create(&tls_key, 0);
|
1999-12-06 05:55:43 +08:00
|
|
|
#endif
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
/* ensure singleton */
|
|
|
|
in_main_thread = 1;
|
2019-06-26 19:18:50 +08:00
|
|
|
is_thread_shutdown = 0;
|
2017-03-04 17:39:13 +08:00
|
|
|
|
2000-11-18 10:41:14 +08:00
|
|
|
tsrm_error_file = stderr;
|
|
|
|
tsrm_error_set(debug_level, debug_filename);
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_tls_table_size = expected_threads;
|
2000-11-18 10:41:14 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_tls_table = (tsrm_tls_entry **) calloc(tsrm_tls_table_size, sizeof(tsrm_tls_entry *));
|
|
|
|
if (!tsrm_tls_table) {
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate TLS table"));
|
2019-06-26 19:18:50 +08:00
|
|
|
is_thread_shutdown = 1;
|
1999-04-21 07:58:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
id_count=0;
|
|
|
|
|
|
|
|
resource_types_table_size = expected_resources;
|
|
|
|
resource_types_table = (tsrm_resource_type *) calloc(resource_types_table_size, sizeof(tsrm_resource_type));
|
|
|
|
if (!resource_types_table) {
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate resource types table"));
|
2019-06-26 19:18:50 +08:00
|
|
|
is_thread_shutdown = 1;
|
1999-04-21 07:58:02 +08:00
|
|
|
free(tsrm_tls_table);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsmm_mutex = tsrm_mutex_alloc();
|
|
|
|
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources));
|
2019-03-14 08:01:01 +08:00
|
|
|
|
|
|
|
tsrm_reserved_pos = 0;
|
|
|
|
tsrm_reserved_size = 0;
|
|
|
|
|
2019-03-29 15:01:31 +08:00
|
|
|
tsrm_env_mutex = tsrm_mutex_alloc();
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
return 1;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Shutdown TSRM (call once for the entire process) */
|
1999-12-06 00:21:37 +08:00
|
|
|
TSRM_API void tsrm_shutdown(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
1999-04-21 07:58:02 +08:00
|
|
|
int i;
|
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
if (is_thread_shutdown) {
|
|
|
|
/* shutdown must only occur once */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_thread_shutdown = 1;
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
if (!in_main_thread) {
|
2019-06-26 19:18:50 +08:00
|
|
|
/* only the main thread may shutdown tsrm */
|
2017-03-04 17:39:13 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
for (i=0; i<tsrm_tls_table_size; i++) {
|
|
|
|
tsrm_tls_entry *p = tsrm_tls_table[i], *next_p;
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
while (p) {
|
|
|
|
int j;
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
next_p = p->next;
|
|
|
|
for (j=0; j<p->count; j++) {
|
|
|
|
if (p->storage[j]) {
|
|
|
|
if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) {
|
|
|
|
resource_types_table[j].dtor(p->storage[j]);
|
|
|
|
}
|
|
|
|
if (!resource_types_table[j].fast_offset) {
|
|
|
|
free(p->storage[j]);
|
2014-09-23 23:14:41 +08:00
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 19:18:50 +08:00
|
|
|
free(p->storage);
|
|
|
|
free(p);
|
|
|
|
p = next_p;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 19:18:50 +08:00
|
|
|
free(tsrm_tls_table);
|
|
|
|
free(resource_types_table);
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_mutex_free(tsmm_mutex);
|
2019-03-29 15:01:31 +08:00
|
|
|
tsrm_mutex_free(tsrm_env_mutex);
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM"));
|
2000-11-18 10:41:14 +08:00
|
|
|
if (tsrm_error_file!=stderr) {
|
|
|
|
fclose(tsrm_error_file);
|
|
|
|
}
|
2019-03-23 15:15:53 +08:00
|
|
|
#if defined(TSRM_WIN32)
|
|
|
|
TlsFree(tls_key);
|
|
|
|
#else
|
2003-08-06 04:03:54 +08:00
|
|
|
pthread_setspecific(tls_key, 0);
|
2001-07-30 13:46:31 +08:00
|
|
|
pthread_key_delete(tls_key);
|
1999-12-06 05:55:43 +08:00
|
|
|
#endif
|
2017-03-04 17:39:13 +08:00
|
|
|
if (tsrm_shutdown_handler) {
|
|
|
|
tsrm_shutdown_handler();
|
|
|
|
}
|
|
|
|
tsrm_new_thread_begin_handler = NULL;
|
|
|
|
tsrm_new_thread_end_handler = NULL;
|
|
|
|
tsrm_shutdown_handler = NULL;
|
2019-03-14 08:01:01 +08:00
|
|
|
|
|
|
|
tsrm_reserved_pos = 0;
|
|
|
|
tsrm_reserved_size = 0;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-29 15:01:31 +08:00
|
|
|
/* {{{ */
|
|
|
|
/* environ lock api */
|
2019-04-11 16:40:54 +08:00
|
|
|
TSRM_API void tsrm_env_lock() {
|
|
|
|
tsrm_mutex_lock(tsrm_env_mutex);
|
2019-03-29 15:01:31 +08:00
|
|
|
}
|
|
|
|
|
2019-04-11 16:40:54 +08:00
|
|
|
TSRM_API void tsrm_env_unlock() {
|
|
|
|
tsrm_mutex_unlock(tsrm_env_mutex);
|
2019-03-29 15:01:31 +08:00
|
|
|
} /* }}} */
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
/* enlarge the arrays for the already active threads */
|
|
|
|
static void tsrm_update_active_threads(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
1999-04-21 07:58:02 +08:00
|
|
|
int i;
|
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
for (i=0; i<tsrm_tls_table_size; i++) {
|
|
|
|
tsrm_tls_entry *p = tsrm_tls_table[i];
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->count < id_count) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count);
|
|
|
|
for (j=p->count; j<id_count; j++) {
|
|
|
|
if (resource_types_table[j].fast_offset) {
|
|
|
|
p->storage[j] = (void *) (((char*)p) + resource_types_table[j].fast_offset);
|
|
|
|
} else {
|
|
|
|
p->storage[j] = (void *) malloc(resource_types_table[j].size);
|
|
|
|
}
|
|
|
|
if (resource_types_table[j].ctor) {
|
|
|
|
resource_types_table[j].ctor(p->storage[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p->count = id_count;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}/*}}}*/
|
|
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{/*{{{*/
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
tsrm_mutex_lock(tsmm_mutex);
|
|
|
|
|
|
|
|
/* obtain a resource id */
|
2001-07-27 18:08:26 +08:00
|
|
|
*rsrc_id = TSRM_SHUFFLE_RSRC_ID(id_count++);
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtained resource id %d", *rsrc_id));
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
/* store the new resource type in the resource sizes table */
|
|
|
|
if (resource_types_table_size < id_count) {
|
2017-10-23 18:50:52 +08:00
|
|
|
tsrm_resource_type *_tmp;
|
|
|
|
_tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
|
|
|
|
if (!_tmp) {
|
2000-11-18 07:31:15 +08:00
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
|
2001-07-27 18:08:26 +08:00
|
|
|
*rsrc_id = 0;
|
2000-11-18 07:31:15 +08:00
|
|
|
return 0;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
2017-10-23 18:50:52 +08:00
|
|
|
resource_types_table = _tmp;
|
1999-04-21 07:58:02 +08:00
|
|
|
resource_types_table_size = id_count;
|
|
|
|
}
|
2001-07-27 18:08:26 +08:00
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
|
2019-03-14 08:01:01 +08:00
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].fast_offset = 0;
|
2004-05-13 06:28:28 +08:00
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].done = 0;
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
tsrm_update_active_threads();
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
|
|
|
|
return *rsrc_id;
|
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2019-03-14 08:01:01 +08:00
|
|
|
|
|
|
|
/* Reserve space for fast thread-safe-resources */
|
|
|
|
TSRM_API void tsrm_reserve(size_t size)
|
|
|
|
{/*{{{*/
|
|
|
|
tsrm_reserved_pos = 0;
|
|
|
|
tsrm_reserved_size = TSRM_ALIGNED_SIZE(size);
|
|
|
|
}/*}}}*/
|
|
|
|
|
|
|
|
|
|
|
|
/* allocates a new fast thread-safe-resource id */
|
|
|
|
TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
|
|
|
|
{/*{{{*/
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new fast resource id, %d bytes", size));
|
|
|
|
|
|
|
|
tsrm_mutex_lock(tsmm_mutex);
|
|
|
|
|
|
|
|
/* obtain a resource id */
|
|
|
|
*rsrc_id = TSRM_SHUFFLE_RSRC_ID(id_count++);
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtained resource id %d", *rsrc_id));
|
|
|
|
|
|
|
|
size = TSRM_ALIGNED_SIZE(size);
|
|
|
|
if (tsrm_reserved_size - tsrm_reserved_pos < size) {
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate space for fast resource"));
|
|
|
|
*rsrc_id = 0;
|
|
|
|
*offset = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset = TSRM_ALIGNED_SIZE(sizeof(tsrm_tls_entry)) + tsrm_reserved_pos;
|
|
|
|
tsrm_reserved_pos += size;
|
|
|
|
|
|
|
|
/* store the new resource type in the resource sizes table */
|
|
|
|
if (resource_types_table_size < id_count) {
|
|
|
|
tsrm_resource_type *_tmp;
|
|
|
|
_tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
|
|
|
|
if (!_tmp) {
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
|
|
|
|
*rsrc_id = 0;
|
|
|
|
return 0;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
2019-03-14 08:01:01 +08:00
|
|
|
resource_types_table = _tmp;
|
|
|
|
resource_types_table_size = id_count;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
2019-03-14 08:01:01 +08:00
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].fast_offset = *offset;
|
|
|
|
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].done = 0;
|
|
|
|
|
|
|
|
tsrm_update_active_threads();
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
|
|
|
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
|
2001-07-27 18:08:26 +08:00
|
|
|
return *rsrc_id;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
1999-04-21 07:58:02 +08:00
|
|
|
int i;
|
|
|
|
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
|
2019-03-14 08:01:01 +08:00
|
|
|
(*thread_resources_ptr) = (tsrm_tls_entry *) malloc(TSRM_ALIGNED_SIZE(sizeof(tsrm_tls_entry)) + tsrm_reserved_size);
|
2015-03-10 02:34:09 +08:00
|
|
|
(*thread_resources_ptr)->storage = NULL;
|
|
|
|
if (id_count > 0) {
|
|
|
|
(*thread_resources_ptr)->storage = (void **) malloc(sizeof(void *)*id_count);
|
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
(*thread_resources_ptr)->count = id_count;
|
|
|
|
(*thread_resources_ptr)->thread_id = thread_id;
|
|
|
|
(*thread_resources_ptr)->next = NULL;
|
1999-10-10 21:30:03 +08:00
|
|
|
|
2001-04-05 00:33:06 +08:00
|
|
|
/* Set thread local storage to this new thread resources structure */
|
2005-04-28 10:55:14 +08:00
|
|
|
tsrm_tls_set(*thread_resources_ptr);
|
2019-03-12 22:35:50 +08:00
|
|
|
TSRMLS_CACHE = *thread_resources_ptr;
|
1999-10-10 21:30:03 +08:00
|
|
|
|
|
|
|
if (tsrm_new_thread_begin_handler) {
|
2014-12-12 15:11:14 +08:00
|
|
|
tsrm_new_thread_begin_handler(thread_id);
|
1999-10-10 21:30:03 +08:00
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
for (i=0; i<id_count; i++) {
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
if (resource_types_table[i].done) {
|
|
|
|
(*thread_resources_ptr)->storage[i] = NULL;
|
2019-03-14 08:01:01 +08:00
|
|
|
} else {
|
|
|
|
if (resource_types_table[i].fast_offset) {
|
|
|
|
(*thread_resources_ptr)->storage[i] = (void *) (((char*)(*thread_resources_ptr)) + resource_types_table[i].fast_offset);
|
|
|
|
} else {
|
|
|
|
(*thread_resources_ptr)->storage[i] = (void *) malloc(resource_types_table[i].size);
|
|
|
|
}
|
2004-05-13 14:53:21 +08:00
|
|
|
if (resource_types_table[i].ctor) {
|
2014-12-16 15:03:15 +08:00
|
|
|
resource_types_table[i].ctor((*thread_resources_ptr)->storage[i]);
|
2004-05-13 14:53:21 +08:00
|
|
|
}
|
1999-04-23 19:00:02 +08:00
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
2001-03-06 23:07:57 +08:00
|
|
|
|
1999-08-14 17:35:52 +08:00
|
|
|
if (tsrm_new_thread_end_handler) {
|
2014-12-12 15:11:14 +08:00
|
|
|
tsrm_new_thread_end_handler(thread_id);
|
1999-08-14 17:35:52 +08:00
|
|
|
}
|
2005-03-20 17:03:40 +08:00
|
|
|
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* fetches the requested resource for the current thread */
|
2000-06-17 22:56:19 +08:00
|
|
|
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2000-06-16 22:38:05 +08:00
|
|
|
THREAD_T thread_id;
|
1999-04-21 07:58:02 +08:00
|
|
|
int hash_value;
|
|
|
|
tsrm_tls_entry *thread_resources;
|
|
|
|
|
2001-04-28 02:50:35 +08:00
|
|
|
if (!th_id) {
|
2001-04-05 00:33:06 +08:00
|
|
|
/* Fast path for looking up the resources for the current
|
2001-07-27 18:08:26 +08:00
|
|
|
* thread. Its used by just about every call to
|
|
|
|
* ts_resource_ex(). This avoids the need for a mutex lock
|
|
|
|
* and our hashtable lookup.
|
|
|
|
*/
|
2005-04-28 10:55:14 +08:00
|
|
|
thread_resources = tsrm_tls_get();
|
|
|
|
|
2001-04-28 02:50:35 +08:00
|
|
|
if (thread_resources) {
|
2001-07-27 18:08:26 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for current thread %d", id, (long) thread_resources->thread_id));
|
|
|
|
/* Read a specific resource from the thread's resources.
|
|
|
|
* This is called outside of a mutex, so have to be aware about external
|
|
|
|
* changes to the structure as we read it.
|
|
|
|
*/
|
|
|
|
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
|
2001-04-05 00:33:06 +08:00
|
|
|
}
|
2000-06-16 22:38:05 +08:00
|
|
|
thread_id = tsrm_thread_id();
|
2001-03-06 23:07:57 +08:00
|
|
|
} else {
|
|
|
|
thread_id = *th_id;
|
2001-04-05 00:33:06 +08:00
|
|
|
}
|
2001-03-06 23:07:57 +08:00
|
|
|
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for thread %ld", id, (long) thread_id));
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_mutex_lock(tsmm_mutex);
|
|
|
|
|
|
|
|
hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size);
|
|
|
|
thread_resources = tsrm_tls_table[hash_value];
|
|
|
|
|
|
|
|
if (!thread_resources) {
|
|
|
|
allocate_new_resource(&tsrm_tls_table[hash_value], thread_id);
|
2001-03-01 09:06:36 +08:00
|
|
|
return ts_resource_ex(id, &thread_id);
|
1999-04-21 07:58:02 +08:00
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (thread_resources->thread_id == thread_id) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (thread_resources->next) {
|
|
|
|
thread_resources = thread_resources->next;
|
|
|
|
} else {
|
|
|
|
allocate_new_resource(&thread_resources->next, thread_id);
|
2001-03-01 09:06:36 +08:00
|
|
|
return ts_resource_ex(id, &thread_id);
|
1999-10-10 21:30:03 +08:00
|
|
|
/*
|
|
|
|
* thread_resources = thread_resources->next;
|
|
|
|
* break;
|
|
|
|
*/
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
|
|
|
} while (thread_resources);
|
|
|
|
}
|
2001-03-06 23:07:57 +08:00
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
2001-07-27 18:08:26 +08:00
|
|
|
/* Read a specific resource from the thread's resources.
|
|
|
|
* This is called outside of a mutex, so have to be aware about external
|
|
|
|
* changes to the structure as we read it.
|
|
|
|
*/
|
|
|
|
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* frees all resources allocated for the current thread */
|
1999-12-06 00:21:37 +08:00
|
|
|
void ts_free_thread(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2001-03-06 23:07:57 +08:00
|
|
|
tsrm_tls_entry *thread_resources;
|
2001-04-05 00:33:06 +08:00
|
|
|
int i;
|
1999-04-21 07:58:02 +08:00
|
|
|
THREAD_T thread_id = tsrm_thread_id();
|
|
|
|
int hash_value;
|
|
|
|
tsrm_tls_entry *last=NULL;
|
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
TSRM_ASSERT(!in_main_thread);
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
tsrm_mutex_lock(tsmm_mutex);
|
|
|
|
hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size);
|
|
|
|
thread_resources = tsrm_tls_table[hash_value];
|
|
|
|
|
|
|
|
while (thread_resources) {
|
|
|
|
if (thread_resources->thread_id == thread_id) {
|
|
|
|
for (i=0; i<thread_resources->count; i++) {
|
1999-04-23 19:00:02 +08:00
|
|
|
if (resource_types_table[i].dtor) {
|
2014-12-16 15:03:15 +08:00
|
|
|
resource_types_table[i].dtor(thread_resources->storage[i]);
|
2001-04-05 00:33:06 +08:00
|
|
|
}
|
|
|
|
}
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
for (i=0; i<thread_resources->count; i++) {
|
2019-03-14 08:01:01 +08:00
|
|
|
if (!resource_types_table[i].fast_offset) {
|
|
|
|
free(thread_resources->storage[i]);
|
|
|
|
}
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
free(thread_resources->storage);
|
2001-04-05 05:43:04 +08:00
|
|
|
if (last) {
|
|
|
|
last->next = thread_resources->next;
|
|
|
|
} else {
|
|
|
|
tsrm_tls_table[hash_value] = thread_resources->next;
|
|
|
|
}
|
2005-04-28 10:55:14 +08:00
|
|
|
tsrm_tls_set(0);
|
1999-04-21 07:58:02 +08:00
|
|
|
free(thread_resources);
|
2001-04-05 05:43:04 +08:00
|
|
|
break;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
|
|
|
if (thread_resources->next) {
|
|
|
|
last = thread_resources;
|
|
|
|
}
|
1999-05-12 05:27:44 +08:00
|
|
|
thread_resources = thread_resources->next;
|
1999-04-21 07:58:02 +08:00
|
|
|
}
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
/* deallocates all occurrences of a given id */
|
|
|
|
void ts_free_id(ts_rsrc_id id)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2004-05-12 18:30:46 +08:00
|
|
|
int i;
|
|
|
|
int j = TSRM_UNSHUFFLE_RSRC_ID(id);
|
|
|
|
|
|
|
|
tsrm_mutex_lock(tsmm_mutex);
|
|
|
|
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Freeing resource id %d", id));
|
|
|
|
|
|
|
|
if (tsrm_tls_table) {
|
|
|
|
for (i=0; i<tsrm_tls_table_size; i++) {
|
2004-05-13 06:28:28 +08:00
|
|
|
tsrm_tls_entry *p = tsrm_tls_table[i];
|
2004-05-12 18:30:46 +08:00
|
|
|
|
|
|
|
while (p) {
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
if (p->count > j && p->storage[j]) {
|
2004-05-12 18:30:46 +08:00
|
|
|
if (resource_types_table && resource_types_table[j].dtor) {
|
2014-12-16 15:03:15 +08:00
|
|
|
resource_types_table[j].dtor(p->storage[j]);
|
2004-05-12 18:30:46 +08:00
|
|
|
}
|
2019-03-14 08:01:01 +08:00
|
|
|
if (!resource_types_table[j].fast_offset) {
|
|
|
|
free(p->storage[j]);
|
|
|
|
}
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
p->storage[j] = NULL;
|
2004-05-12 18:30:46 +08:00
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-13 06:28:28 +08:00
|
|
|
resource_types_table[j].done = 1;
|
2004-05-12 18:30:46 +08:00
|
|
|
|
|
|
|
tsrm_mutex_unlock(tsmm_mutex);
|
|
|
|
|
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id));
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Obtain the current thread id */
|
1999-08-14 17:35:52 +08:00
|
|
|
TSRM_API THREAD_T tsrm_thread_id(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2000-09-02 23:03:19 +08:00
|
|
|
#ifdef TSRM_WIN32
|
1999-04-21 07:58:02 +08:00
|
|
|
return GetCurrentThreadId();
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
1999-04-21 07:58:02 +08:00
|
|
|
return pthread_self();
|
|
|
|
#endif
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Allocate a mutex */
|
2000-11-18 07:31:15 +08:00
|
|
|
TSRM_API MUTEX_T tsrm_mutex_alloc(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2002-10-05 19:34:02 +08:00
|
|
|
MUTEX_T mutexp;
|
2000-09-02 23:03:19 +08:00
|
|
|
#ifdef TSRM_WIN32
|
2002-10-05 19:34:02 +08:00
|
|
|
mutexp = malloc(sizeof(CRITICAL_SECTION));
|
1999-12-21 04:02:25 +08:00
|
|
|
InitializeCriticalSection(mutexp);
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
1999-04-21 07:58:02 +08:00
|
|
|
mutexp = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
|
|
|
|
pthread_mutex_init(mutexp,NULL);
|
|
|
|
#endif
|
|
|
|
#ifdef THR_DEBUG
|
2002-10-05 19:34:02 +08:00
|
|
|
printf("Mutex created thread: %d\n",mythreadid());
|
1999-04-21 07:58:02 +08:00
|
|
|
#endif
|
2002-10-05 19:34:02 +08:00
|
|
|
return( mutexp );
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Free a mutex */
|
2000-11-18 07:31:15 +08:00
|
|
|
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2002-10-05 19:34:02 +08:00
|
|
|
if (mutexp) {
|
2000-09-02 23:03:19 +08:00
|
|
|
#ifdef TSRM_WIN32
|
1999-12-21 04:02:25 +08:00
|
|
|
DeleteCriticalSection(mutexp);
|
2003-06-25 13:05:06 +08:00
|
|
|
free(mutexp);
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
1999-11-26 23:33:42 +08:00
|
|
|
pthread_mutex_destroy(mutexp);
|
1999-12-06 05:55:43 +08:00
|
|
|
free(mutexp);
|
1999-04-21 07:58:02 +08:00
|
|
|
#endif
|
2002-10-05 19:34:02 +08:00
|
|
|
}
|
1999-04-21 07:58:02 +08:00
|
|
|
#ifdef THR_DEBUG
|
2002-10-05 19:34:02 +08:00
|
|
|
printf("Mutex freed thread: %d\n",mythreadid());
|
1999-04-21 07:58:02 +08:00
|
|
|
#endif
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
2008-02-07 17:06:45 +08:00
|
|
|
/*
|
|
|
|
Lock a mutex.
|
|
|
|
A return value of 0 indicates success
|
|
|
|
*/
|
2000-11-18 07:31:15 +08:00
|
|
|
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
|
2000-09-02 23:03:19 +08:00
|
|
|
#ifdef TSRM_WIN32
|
1999-12-21 04:02:25 +08:00
|
|
|
EnterCriticalSection(mutexp);
|
2008-02-07 17:06:45 +08:00
|
|
|
return 0;
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
1999-04-21 07:58:02 +08:00
|
|
|
return pthread_mutex_lock(mutexp);
|
|
|
|
#endif
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
2008-02-07 17:06:45 +08:00
|
|
|
/*
|
|
|
|
Unlock a mutex.
|
|
|
|
A return value of 0 indicates success
|
|
|
|
*/
|
2000-11-18 07:31:15 +08:00
|
|
|
TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2001-07-23 12:16:31 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id()));
|
2000-09-02 23:03:19 +08:00
|
|
|
#ifdef TSRM_WIN32
|
1999-12-21 04:02:25 +08:00
|
|
|
LeaveCriticalSection(mutexp);
|
2008-02-07 17:06:45 +08:00
|
|
|
return 0;
|
2019-03-23 15:15:53 +08:00
|
|
|
#else
|
1999-04-21 07:58:02 +08:00
|
|
|
return pthread_mutex_unlock(mutexp);
|
|
|
|
#endif
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2011-06-03 05:16:50 +08:00
|
|
|
/*
|
|
|
|
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)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2011-06-03 05:16:50 +08:00
|
|
|
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Changed sigmask in thread: %ld", tsrm_thread_id()));
|
2019-03-23 15:15:53 +08:00
|
|
|
|
|
|
|
return pthread_sigmask(how, set, oldset);
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2011-06-03 05:16:50 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
|
2001-07-30 09:46:35 +08:00
|
|
|
TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
1999-08-14 17:35:52 +08:00
|
|
|
void *retval = (void *) tsrm_new_thread_begin_handler;
|
|
|
|
|
|
|
|
tsrm_new_thread_begin_handler = new_thread_begin_handler;
|
|
|
|
return retval;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-08-14 17:35:52 +08:00
|
|
|
|
|
|
|
|
2001-07-30 09:46:35 +08:00
|
|
|
TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
1999-08-14 17:35:52 +08:00
|
|
|
void *retval = (void *) tsrm_new_thread_end_handler;
|
|
|
|
|
|
|
|
tsrm_new_thread_end_handler = new_thread_end_handler;
|
|
|
|
return retval;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
1999-08-14 17:35:52 +08:00
|
|
|
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2017-03-04 17:39:13 +08:00
|
|
|
void *retval = (void *) tsrm_shutdown_handler;
|
|
|
|
|
|
|
|
tsrm_shutdown_handler = shutdown_handler;
|
|
|
|
return retval;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2017-03-04 17:39:13 +08:00
|
|
|
|
1999-08-14 17:35:52 +08:00
|
|
|
|
1999-04-21 07:58:02 +08:00
|
|
|
/*
|
|
|
|
* Debug support
|
|
|
|
*/
|
|
|
|
|
2000-11-18 10:41:14 +08:00
|
|
|
#if TSRM_DEBUG
|
|
|
|
int tsrm_error(int level, const char *format, ...)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2000-11-18 07:31:15 +08:00
|
|
|
if (level<=tsrm_error_level) {
|
1999-04-21 07:58:02 +08:00
|
|
|
va_list args;
|
|
|
|
int size;
|
|
|
|
|
2000-11-18 10:41:14 +08:00
|
|
|
fprintf(tsrm_error_file, "TSRM: ");
|
1999-04-21 07:58:02 +08:00
|
|
|
va_start(args, format);
|
2000-11-18 10:41:14 +08:00
|
|
|
size = vfprintf(tsrm_error_file, format, args);
|
1999-04-21 07:58:02 +08:00
|
|
|
va_end(args);
|
2000-11-18 10:41:14 +08:00
|
|
|
fprintf(tsrm_error_file, "\n");
|
|
|
|
fflush(tsrm_error_file);
|
1999-04-21 07:58:02 +08:00
|
|
|
return size;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2000-11-18 10:41:14 +08:00
|
|
|
#endif
|
1999-04-21 07:58:02 +08:00
|
|
|
|
|
|
|
|
2000-11-18 10:41:14 +08:00
|
|
|
void tsrm_error_set(int level, char *debug_filename)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2000-11-18 07:31:15 +08:00
|
|
|
tsrm_error_level = level;
|
2000-11-18 10:41:14 +08:00
|
|
|
|
|
|
|
#if TSRM_DEBUG
|
|
|
|
if (tsrm_error_file!=stderr) { /* close files opened earlier */
|
|
|
|
fclose(tsrm_error_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug_filename) {
|
|
|
|
tsrm_error_file = fopen(debug_filename, "w");
|
|
|
|
if (!tsrm_error_file) {
|
|
|
|
tsrm_error_file = stderr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tsrm_error_file = stderr;
|
|
|
|
}
|
|
|
|
#endif
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2000-09-01 07:44:10 +08:00
|
|
|
|
2014-12-22 03:01:39 +08:00
|
|
|
TSRM_API void *tsrm_get_ls_cache(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
return tsrm_tls_get();
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2014-09-23 02:58:45 +08:00
|
|
|
|
2019-04-01 15:27:11 +08:00
|
|
|
/* Returns offset of tsrm_ls_cache slot from Thread Control Block address */
|
|
|
|
TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
|
|
|
|
{/*{{{*/
|
2019-06-17 22:08:58 +08:00
|
|
|
#if defined(__APPLE__) && defined(__x86_64__)
|
|
|
|
// TODO: Implement support for fast JIT ZTS code ???
|
|
|
|
return 0;
|
|
|
|
#elif defined(__x86_64__) && defined(__GNUC__)
|
2019-04-01 15:27:11 +08:00
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
asm ("movq _tsrm_ls_cache@gottpoff(%%rip),%0"
|
|
|
|
: "=r" (ret));
|
|
|
|
return ret;
|
|
|
|
#elif defined(__i386__) && defined(__GNUC__)
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
asm ("leal _tsrm_ls_cache@ntpoff,%0"
|
|
|
|
: "=r" (ret));
|
|
|
|
return ret;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}/*}}}*/
|
|
|
|
|
2017-04-15 20:28:58 +08:00
|
|
|
TSRM_API uint8_t tsrm_is_main_thread(void)
|
2017-07-04 23:06:52 +08:00
|
|
|
{/*{{{*/
|
2017-04-15 20:28:58 +08:00
|
|
|
return in_main_thread;
|
2017-07-04 23:06:52 +08:00
|
|
|
}/*}}}*/
|
2017-04-15 20:28:58 +08:00
|
|
|
|
2019-06-26 19:18:50 +08:00
|
|
|
TSRM_API uint8_t tsrm_is_shutdown(void)
|
|
|
|
{/*{{{*/
|
|
|
|
return is_thread_shutdown;
|
|
|
|
}/*}}}*/
|
|
|
|
|
2017-12-22 00:54:31 +08:00
|
|
|
TSRM_API const char *tsrm_api_name(void)
|
|
|
|
{/*{{{*/
|
2019-03-23 15:15:53 +08:00
|
|
|
#if defined(TSRM_WIN32)
|
2017-12-22 00:54:31 +08:00
|
|
|
return "Windows Threads";
|
|
|
|
#else
|
2019-03-23 15:15:53 +08:00
|
|
|
return "POSIX Threads";
|
2017-12-22 00:54:31 +08:00
|
|
|
#endif
|
|
|
|
}/*}}}*/
|
|
|
|
|
2000-09-01 07:44:10 +08:00
|
|
|
#endif /* ZTS */
|