Skip to content

Commit

Permalink
Clean up some WIN_THREADS loose ends
Browse files Browse the repository at this point in the history
Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Mar 20, 2024
1 parent 4f04df9 commit 4e05769
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/H5.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ H5_init_library(void)
* executed in LIFO order (i.e., last).
*/
(void)atexit(H5TS_term_package);
#endif /* H5_HAVE_THREADSAFE && H5_HAVE_WIN_THREADS */
#endif /* H5_HAVE_THREADSAFE */

/* Normal library termination code */
(void)atexit(H5_term_library);
Expand Down
23 changes: 9 additions & 14 deletions src/H5TSprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#define H5TS_thread_equal(t1, t2) (GetThreadId(t1) == GetThreadId(t2))
#else
#define H5TS_thread_self() pthread_self()
#define H5TS_thread_equal(t1, t2) pthread_equal(t1, t2)
#define H5TS_thread_equal(t1, t2) pthread_equal((t1), (t2))
#endif

/****************************/
Expand Down Expand Up @@ -92,21 +92,16 @@ typedef pthread_once_t H5TS_once_t;
typedef void (*H5TS_once_init_func_t)(void);
#endif

/*****************************/
/* Library-private Variables */
/*****************************/
/*****************************/
/* Library-private Variables */
/*****************************/

/***************************************/
/* Library-private Function Prototypes */
/***************************************/
/***************************************/
/* Library-private Function Prototypes */
/***************************************/

/* Library/thread init/term operations */
H5_DLL void
H5TS_term_package(void);
#ifdef H5_HAVE_WIN_THREADS
H5_DLL herr_t H5TS_win32_thread_enter(void);
H5_DLL herr_t H5TS_win32_thread_exit(void);
#endif /* H5_HAVE_WIN_THREADS */
/* Library/thread init/term operations */
H5_DLL void H5TS_term_package(void);

/* API locking */
H5_DLL herr_t H5TS_api_lock(void);
Expand Down
42 changes: 25 additions & 17 deletions src/H5TSwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
/********************/
/* Local Prototypes */
/********************/
#if defined(H5_BUILT_AS_DYNAMIC_LIB) && defined(H5_HAVE_WIN32_API)
static herr_t H5TS__win32_thread_enter(void);
static herr_t H5TS__win32_thread_exit(void);
#endif

/*********************/
/* Package Variables */
Expand Down Expand Up @@ -94,38 +98,43 @@ H5TS__win32_process_enter(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex)
FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value)
} /* H5TS__win32_process_enter() */

#if defined(H5_BUILT_AS_DYNAMIC_LIB) && defined(H5_HAVE_WIN32_API)
/*--------------------------------------------------------------------------
* Function: H5TS_win32_thread_enter
* Function: H5TS__win32_thread_enter
*
* Purpose: Per-thread setup on Windows when using Win32 threads.
*
* Return: Non-negative on success / Negative on failure
*
*--------------------------------------------------------------------------
*/
herr_t
H5TS_win32_thread_enter(void){FUNC_ENTER_NOAPI_NAMECHECK_ONLY
static herr_t
H5TS__win32_thread_enter(void)
{
FUNC_ENTER_NOAPI_NAMECHECK_ONLY

/* Currently a placeholder function. TLS setup is performed
* elsewhere in the library.
*
* WARNING: Do NOT use C standard library functions here.
* CRT functions are not allowed in DllMain, which is where this code
* is used.
*/
/* Currently a placeholder function. TLS setup is performed
* elsewhere in the library.
*
* WARNING: Do NOT use C standard library functions here.
* CRT functions are not allowed in DllMain, which is where this code
* is used.
*/

FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(SUCCEED)} /* H5TS_win32_thread_enter() */
FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(SUCCEED)
} /* H5TS__win32_thread_enter() */

/*--------------------------------------------------------------------------
* Function: H5TS_win32_thread_exit
* Function: H5TS__win32_thread_exit
*
* Purpose: Per-thread cleanup on Windows when using Win32 threads.
*
* Return: Non-negative on success / Negative on failure
*
*--------------------------------------------------------------------------
*/
herr_t H5TS_win32_thread_exit(void)
static herr_t
H5TS__win32_thread_exit(void)
{
herr_t ret_value = SUCCEED;

Expand All @@ -151,9 +160,8 @@ herr_t H5TS_win32_thread_exit(void)

done:
FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value)
} /* H5TS_win32_thread_exit() */
} /* H5TS__win32_thread_exit() */

#if defined(H5_BUILT_AS_DYNAMIC_LIB) && defined(H5_HAVE_WIN32_API)
/*-------------------------------------------------------------------------
* Function: DllMain
*
Expand Down Expand Up @@ -189,12 +197,12 @@ DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
break;

case DLL_THREAD_ATTACH:
if (H5TS_win32_thread_enter() < 0)
if (H5TS__win32_thread_enter() < 0)
fOkay = false;
break;

case DLL_THREAD_DETACH:
if (H5TS_win32_thread_exit() < 0)
if (H5TS__win32_thread_exit() < 0)
fOkay = false;
break;

Expand Down

0 comments on commit 4e05769

Please sign in to comment.