free TLS slot properly on Windows
Gurusamy Sarathy [Mon, 21 Aug 2000 16:22:19 +0000 (16:22 +0000)]
p4raw-id: //depot/perl@6748

thread.h
win32/perllib.c
win32/win32thread.h

index 206a5c5..9740dba 100644 (file)
--- a/thread.h
+++ b/thread.h
 #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 */
     } 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))
index fae3346..e2b245d 100644 (file)
@@ -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. */
index 809e0f7..a52118b 100644 (file)
@@ -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 {                                                       \