From 072eb6dd77b079a6f90ca5b155f9b0add1b5f2d4 Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Fri, 29 Mar 2019 08:01:31 +0100 Subject: tsrm environment lock --- TSRM/TSRM.c | 16 +++++++++++++++- TSRM/TSRM.h | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'TSRM') diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index 670c260678..d70c09d2b5 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -52,7 +52,8 @@ static int resource_types_table_size; static size_t tsrm_reserved_pos = 0; static size_t tsrm_reserved_size = 0; -static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ +static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ +static MUTEX_T tsrm_env_mutex; /* tsrm environ mutex */ /* New thread handlers */ static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler = NULL; @@ -168,6 +169,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu tsrm_reserved_pos = 0; tsrm_reserved_size = 0; + tsrm_env_mutex = tsrm_mutex_alloc(); + return 1; }/*}}}*/ @@ -214,6 +217,8 @@ TSRM_API void tsrm_shutdown(void) } tsrm_mutex_free(tsmm_mutex); tsmm_mutex = NULL; + tsrm_mutex_free(tsrm_env_mutex); + tsrm_env_mutex = NULL; TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM")); if (tsrm_error_file!=stderr) { fclose(tsrm_error_file); @@ -237,6 +242,15 @@ TSRM_API void tsrm_shutdown(void) tsrm_reserved_size = 0; }/*}}}*/ +/* {{{ */ +/* environ lock api */ +TSRM_API int tsrm_env_lock() { + return tsrm_mutex_lock(tsrm_env_mutex); +} + +TSRM_API int tsrm_env_unlock() { + return tsrm_mutex_unlock(tsrm_env_mutex); +} /* }}} */ /* enlarge the arrays for the already active threads */ static void tsrm_update_active_threads(void) diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index a14e31e1f0..5e1f8164ee 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -99,6 +99,10 @@ extern "C" { TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename); TSRM_API void tsrm_shutdown(void); +/* environ lock API */ +TSRM_API int tsrm_env_lock(); +TSRM_API int tsrm_env_unlock(); + /* 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); @@ -205,6 +209,9 @@ TSRM_API const char *tsrm_api_name(void); #else /* non ZTS */ +#define tsrm_env_lock() 0 +#define tsrm_env_unlock() 0 + #define TSRMLS_FETCH() #define TSRMLS_FETCH_FROM_CTX(ctx) #define TSRMLS_SET_CTX(ctx) -- cgit v1.2.1