From e1b5da6416e0c12378554a33f21a92b0a14593e9 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Mon, 21 Aug 2000 16:22:19 +0000 Subject: [PATCH] free TLS slot properly on Windows p4raw-id: //depot/perl@6748 --- thread.h | 8 ++++++++ win32/perllib.c | 4 ++++ win32/win32thread.h | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/thread.h b/thread.h index 206a5c5..9740dba 100644 --- a/thread.h +++ b/thread.h @@ -117,6 +117,7 @@ #define INIT_THREADS cthread_init() #define YIELD cthread_yield() #define ALLOC_THREAD_KEY NOOP +#define FREE_THREAD_KEY NOOP #define SET_THREAD_SELF(thr) (thr->self = cthread_self()) #endif /* I_MACH_CTHREADS */ @@ -257,6 +258,13 @@ } STMT_END #endif +#ifndef FREE_THREAD_KEY +# define FREE_THREAD_KEY \ + STMT_START { \ + pthread_key_delete(PL_thr_key); \ + } STMT_END +#endif + #ifndef THREAD_RET_TYPE # define THREAD_RET_TYPE void * # define THREAD_RET_CAST(p) ((void *)(p)) diff --git a/win32/perllib.c b/win32/perllib.c index fae3346..e2b245d 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -372,6 +372,10 @@ DllMain(HANDLE hModule, /* DLL module handle */ */ case DLL_PROCESS_DETACH: EndSockets(); +#if defined(USE_THREADS) || defined(USE_ITHREADS) + if (PL_curinterp) + FREE_THREAD_KEY; +#endif break; /* The attached process creates a new thread. */ diff --git a/win32/win32thread.h b/win32/win32thread.h index 809e0f7..a52118b 100644 --- a/win32/win32thread.h +++ b/win32/win32thread.h @@ -175,6 +175,11 @@ END_EXTERN_C } \ } STMT_END +#define FREE_THREAD_KEY \ + STMT_START { \ + TlsFree(PL_thr_key); \ + } STMT_END + #if defined(USE_RTL_THREAD_API) && !defined(_MSC_VER) #define JOIN(t, avp) \ STMT_START { \ -- 2.7.4