summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5.c')
-rw-r--r--src/H5.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/src/H5.c b/src/H5.c
index d299102..d6d321a 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -152,13 +152,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 */
@@ -346,7 +356,7 @@ H5_term_library(void)
done:
#ifdef H5_HAVE_THREADSAFE
H5_API_UNLOCK
-#endif
+#endif /* H5_HAVE_THREADSAFE */
return;
} /* end H5_term_library() */
@@ -874,3 +884,65 @@ uint32_t H5checksum(const void *key, size_t length, H5_checksum_seed_t *cs)
done:
FUNC_LEAVE_API(ret_value)
} /* end H5checksum */
+
+
+#if defined(H5_HAVE_THREADSAFE) && defined(H5_BUILT_AS_DYNAMIC_LIB) \
+ && defined(H5_HAVE_WIN32_API) && defined(H5_HAVE_WIN_THREADS)
+/*-------------------------------------------------------------------------
+ * 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.
+ *
+ * Only enabled when the shared Windows library is built with
+ * thread safety enabled.
+ *
+ * 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 && H5_BUILT_AS_DYNAMIC_LIB && H5_HAVE_WIN_THREADS && H5_HAVE_THREADSAFE*/