summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-18 06:37:41 -0700
committerEdward Thomson <ethomson@github.com>2016-03-18 06:37:41 -0700
commitec5a43b60ab0dfcb42db8101edfca34be3d62947 (patch)
treec72fccc4419dab3324d90375eb740313548bef6c
parent3a43677ec67cb528b01138b320d4472dfcd04e2c (diff)
parenta177756b34e7fe9472ec9a6a92805add70cd6815 (diff)
downloadlibgit2-ec5a43b60ab0dfcb42db8101edfca34be3d62947.tar.gz
Merge pull request #3699 from libgit2/cmn/win32-free-tls
win32: free thread-local data on thread exit
-rw-r--r--src/global.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/global.c b/src/global.c
index cbd12ddda..acca59985 100644
--- a/src/global.c
+++ b/src/global.c
@@ -226,6 +226,20 @@ void git__free_tls_data(void)
TlsSetValue(_tls_index, NULL);
}
+BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
+{
+ /* This is how Windows lets us know our thread is being shut down */
+ if (fdwReason == DLL_THREAD_DETACH) {
+ git__free_tls_data();
+ }
+
+ /*
+ * Windows pays attention to this during library loading. We don't do anything
+ * so we trivially succeed.
+ */
+ return TRUE;
+}
+
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
static pthread_key_t _tls_key;