diff options
Diffstat (limited to 'src/H5.c')
-rw-r--r-- | src/H5.c | 73 |
1 files changed, 70 insertions, 3 deletions
@@ -151,13 +151,23 @@ H5_init_library(void) #endif /* - * Install atexit() library cleanup routine unless the H5dont_atexit() + * Install atexit() library cleanup routines unless the H5dont_atexit() * has been called. Once we add something to the atexit() list it stays * there permanently, so we set H5_dont_atexit_g after we add it to prevent * adding it again later if the library is cosed and reopened. */ if (!H5_dont_atexit_g) { - (void)HDatexit(H5_term_library); + +#if defined(H5_HAVE_THREADSAFE) && defined(H5_HAVE_WIN_THREADS) + /* Clean up Win32 thread resources. Pthreads automatically cleans up. + * This must be entered before the library cleanup code so it's + * executed in LIFO order (i.e., last). + */ + (void)HDatexit(H5TS_win32_process_exit); +#endif /* H5_HAVE_THREADSAFE && H5_HAVE_WIN_THREADS */ + + /* Normal library termination code */ + (void)HDatexit(H5_term_library); H5_dont_atexit_g = TRUE; } /* end if */ @@ -330,7 +340,7 @@ H5_term_library(void) done: #ifdef H5_HAVE_THREADSAFE H5_API_UNLOCK -#endif +#endif /* H5_HAVE_THREADSAFE */ return; } /* end H5_term_library() */ @@ -831,3 +841,60 @@ H5free_memory(void *mem) FUNC_LEAVE_API(SUCCEED) } /* end H5free_memory() */ + +#ifdef H5_HAVE_WIN32_API +/*------------------------------------------------------------------------- + * Function: DllMain + * + * Purpose: Handles various conditions in the library on Windows. + * + * NOTE: The main purpose of this is for handling Win32 thread cleanup + * on thread/process detach. + * + * Return: TRUE on success, FALSE on failure + * + *------------------------------------------------------------------------- + */ +BOOL WINAPI +DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved) +{ + /* Don't add our function enter/leave macros since this function will be + * called before the library is initialized. + * + * NOTE: Do NOT call any CRT functions in DllMain! + * This includes any functions that are called by from here! + */ + + BOOL fOkay = TRUE; + + switch(fdwReason) + { + case DLL_PROCESS_ATTACH: + break; + + case DLL_PROCESS_DETACH: + break; + + case DLL_THREAD_ATTACH: +#ifdef H5_HAVE_WIN_THREADS + if(H5TS_win32_thread_enter() < 0) + fOkay = FALSE; +#endif /* H5_HAVE_WIN_THREADS */ + break; + + case DLL_THREAD_DETACH: +#ifdef H5_HAVE_WIN_THREADS + if(H5TS_win32_thread_exit() < 0) + fOkay = FALSE; +#endif /* H5_HAVE_WIN_THREADS */ + break; + + default: + /* Shouldn't get here */ + fOkay = FALSE; + break; + } + + return fOkay; +} +#endif /* H5_HAVE_WIN32_API */ |