summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
authorMohamad Chaarawi <chaarawi@hdfgroup.org>2014-06-11 13:44:37 (GMT)
committerMohamad Chaarawi <chaarawi@hdfgroup.org>2014-06-11 13:44:37 (GMT)
commit3e1e5f166a1316573ea81b96178bb6a4fa3654a2 (patch)
tree117c2d8a7a50c4b345784738bdc776ec540fc1db /src/H5.c
parent72e8017eadf211257caceb43095b2aed76e81632 (diff)
parentd86717819242c706a34abf2d2bdb64baebfe1818 (diff)
downloadhdf5-3e1e5f166a1316573ea81b96178bb6a4fa3654a2.zip
hdf5-3e1e5f166a1316573ea81b96178bb6a4fa3654a2.tar.gz
hdf5-3e1e5f166a1316573ea81b96178bb6a4fa3654a2.tar.bz2
[svn-r25254] merge from trunk.
Diffstat (limited to 'src/H5.c')
-rw-r--r--src/H5.c73
1 files changed, 70 insertions, 3 deletions
diff --git a/src/H5.c b/src/H5.c
index f6bf87c..856aad5 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 */
@@ -333,7 +343,7 @@ H5_term_library(void)
done:
#ifdef H5_HAVE_THREADSAFE
H5_API_UNLOCK
-#endif
+#endif /* H5_HAVE_THREADSAFE */
return;
} /* end H5_term_library() */
@@ -834,3 +844,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 */