diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-09-15 14:49:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-09-15 14:49:13 (GMT) |
commit | f0939c320dd3ad761aba4edfdbd63c4b2829f20c (patch) | |
tree | 1f82bf453de01dc4cc56d9c17510f7ed34b11565 | |
parent | 2e7ab5f65fbf01a45f45713d7b77062bb852e119 (diff) | |
download | hdf5-f0939c320dd3ad761aba4edfdbd63c4b2829f20c.zip hdf5-f0939c320dd3ad761aba4edfdbd63c4b2829f20c.tar.gz hdf5-f0939c320dd3ad761aba4edfdbd63c4b2829f20c.tar.bz2 |
[svn-r19385] Description:
Bring r19384 from trunk to 1.8 branch:
Correct an error I convinced Mike to introduce with the phread_once()
code, :-( along with another one that wasn't my fault. Also, clean up
warnings and restructure code in the pthread side of the thread-safe code a bit.
Tested on:
Mac OS X/32 10.6.4 (amazon) w/production + thread-safe
(not a configuration that h5committest tests)
-rw-r--r-- | src/H5TS.c | 93 | ||||
-rw-r--r-- | src/H5TSprivate.h | 2 | ||||
-rw-r--r-- | src/H5private.h | 8 |
3 files changed, 50 insertions, 53 deletions
@@ -29,7 +29,11 @@ typedef struct H5TS_cancel_struct { } H5TS_cancel_t; /* Global variable definitions */ +#ifdef H5_HAVE_WIN_THREADS H5TS_once_t H5TS_first_init_g; +#else /* H5_HAVE_WIN_THREADS */ +H5TS_once_t H5TS_first_init_g = PTHREAD_ONCE_INIT; +#endif /* H5_HAVE_WIN_THREADS */ H5TS_key_t H5TS_errstk_key_g; H5TS_key_t H5TS_funcstk_key_g; H5TS_key_t H5TS_cancel_key_g; @@ -64,12 +68,45 @@ H5TS_key_destructor(void *key_val) HDfree(key_val); } +#ifdef H5_HAVE_WIN_THREADS + +/*-------------------------------------------------------------------------- + * NAME + * H5TS_win32_first_thread_init + * + * USAGE + * H5TS_win32_first_thread_init() + * + * RETURNS + * + * DESCRIPTION + * Special function on windows needed to call the H5TS_first_thread_init + * function. + * + * PROGRAMMER: Mike McGreevy + * September 1, 2010 + * + * MODIFICATIONS: + * + *-------------------------------------------------------------------------- + */ +BOOL CALLBACK +H5TS_win32_first_thread_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex) +{ + InitializeCriticalSection ( &H5_g.init_lock.CriticalSection ); + H5TS_errstk_key_g = TlsAlloc(); + H5TS_funcstk_key_g = TlsAlloc(); + H5TS_cancel_key_g = TlsAlloc(); + + return TRUE; +} /* H5TS_win32_first_thread_init() */ +#else /* H5_HAVE_WIN_THREADS */ /*-------------------------------------------------------------------------- * NAME - * H5TS_first_thread_init + * H5TS_pthread_first_thread_init * * USAGE - * H5TS_first_thread_init() + * H5TS_pthread_first_thread_init() * * RETURNS * @@ -86,15 +123,10 @@ H5TS_key_destructor(void *key_val) *-------------------------------------------------------------------------- */ void -H5TS_first_thread_init(void) +H5TS_pthread_first_thread_init(void) { -#ifdef H5_HAVE_WIN_THREADS - InitializeCriticalSection ( &H5_g.init_lock.CriticalSection ); - H5TS_errstk_key_g = TlsAlloc(); - H5TS_funcstk_key_g = TlsAlloc(); - H5TS_cancel_key_g = TlsAlloc(); -#else /* H5_HAVE_WIN_THREADS */ H5_g.H5_libinit_g = FALSE; + /* initialize global API mutex lock */ pthread_mutex_init(&H5_g.init_lock.atomic_lock, NULL); pthread_cond_init(&H5_g.init_lock.cond_var, NULL); @@ -108,38 +140,8 @@ H5TS_first_thread_init(void) /* initialize key for thread cancellability mechanism */ pthread_key_create(&H5TS_cancel_key_g, H5TS_key_destructor); -#endif /* H5_HAVE_WIN_THREADS */ } - - -/*-------------------------------------------------------------------------- - * NAME - * H5TS_win32_first_thread_init - * - * USAGE - * H5TS_win32_first_thread_init() - * - * RETURNS - * - * DESCRIPTION - * Special function on windows needed to call the H5TS_first_thread_init - * function. - * - * PROGRAMMER: Mike McGreevy - * September 1, 2010 - * - * MODIFICATIONS: - * - *-------------------------------------------------------------------------- - */ -#ifdef H5_HAVE_WIN_THREADS -BOOL CALLBACK -H5TS_win32_first_thread_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex) -{ - H5TS_first_thread_init(); - return TRUE; -} /* H5TS_win32_first_thread_init() */ -#endif +#endif /* H5_HAVE_WIN_THREADS */ /*-------------------------------------------------------------------------- * NAME @@ -290,14 +292,14 @@ H5TS_cancel_count_inc(void) H5TS_cancel_t *cancel_counter; herr_t ret_value = SUCCEED; - cancel_counter = H5TS_get_thread_local_value(H5TS_cancel_key_g); + cancel_counter = (H5TS_cancel_t *)H5TS_get_thread_local_value(H5TS_cancel_key_g); if (!cancel_counter) { /* * First time thread calls library - create new counter and associate * with key */ - cancel_counter = H5MM_calloc(sizeof(H5TS_cancel_t)); + cancel_counter = (H5TS_cancel_t *)H5MM_calloc(sizeof(H5TS_cancel_t)); if (!cancel_counter) { H5E_push_stack(NULL, "H5TS_cancel_count_inc", @@ -354,11 +356,10 @@ H5TS_cancel_count_dec(void) /* unsupported; will just return 0 */ return SUCCEED; #else /* H5_HAVE_WIN_THREADS */ - H5E_t *estack = NULL; + register H5TS_cancel_t *cancel_counter; herr_t ret_value = SUCCEED; - register H5TS_cancel_t *cancel_counter; - cancel_counter = H5TS_get_thread_local_value(H5TS_cancel_key_g); + cancel_counter = (H5TS_cancel_t *)H5TS_get_thread_local_value(H5TS_cancel_key_g); if (cancel_counter->cancel_count == 1) ret_value = pthread_setcancelstate(cancel_counter->previous_state, NULL); @@ -396,7 +397,7 @@ H5TS_create_thread(void * func, H5TS_attr_t * attr, void*udata) #else /* H5_HAVE_WIN_THREADS */ - pthread_create(&ret_value, attr, func, udata); + pthread_create(&ret_value, attr, (void * (*)(void *))func, udata); #endif /* H5_HAVE_WIN_THREADS */ diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index 964dcf3..7f55f4f 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -110,7 +110,7 @@ extern "C" { #endif /* c_plusplus || __cplusplus */ -H5_DLL void H5TS_first_thread_init(void); +H5_DLL void H5TS_pthread_first_thread_init(void); H5_DLL herr_t H5TS_mutex_lock(H5TS_mutex_t *mutex); H5_DLL herr_t H5TS_mutex_unlock(H5TS_mutex_t *mutex); H5_DLL herr_t H5TS_cancel_count_inc(void); diff --git a/src/H5private.h b/src/H5private.h index 4f67326..518b503 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1665,13 +1665,9 @@ typedef struct H5_api_struct { /* Macro for first thread initialization */ #ifdef H5_HAVE_WIN_THREADS -#define H5_FIRST_THREAD_INIT \ - if (!H5_INIT_GLOBAL) \ - InitOnceExecuteOnce(&H5TS_first_init_g, H5TS_win32_first_thread_init, NULL, NULL); +#define H5_FIRST_THREAD_INIT InitOnceExecuteOnce(&H5TS_first_init_g, H5TS_win32_first_thread_init, NULL, NULL); #else -#define H5_FIRST_THREAD_INIT \ - if (!H5_INIT_GLOBAL) \ - pthread_once(&H5TS_first_init_g, H5TS_first_thread_init); +#define H5_FIRST_THREAD_INIT pthread_once(&H5TS_first_init_g, H5TS_pthread_first_thread_init); #endif /* Macros for threadsafe HDF-5 Phase I locks */ |