X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/ea0efc06fdad2019ffceb86d079dd853e9d79cea..4d0de388c25e109e75877045fe621a16d4bae1c5:/win32/win32thread.c diff --git a/win32/win32thread.c b/win32/win32thread.c index e74d7e8..1f327d6 100644 --- a/win32/win32thread.c +++ b/win32/win32thread.c @@ -1,30 +1,37 @@ #include "EXTERN.h" #include "perl.h" -#include "win32/win32thread.h" + +#ifdef USE_DECLSPEC_THREAD +__declspec(thread) void *PL_current_context = NULL; +#endif void -init_thread_intern(struct thread *thr) +Perl_set_context(void *t) { - DuplicateHandle(GetCurrentProcess(), - GetCurrentThread(), - GetCurrentProcess(), - &self, - 0, - FALSE, - DUPLICATE_SAME_ACCESS); - if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) - croak("panic: TlsAlloc"); - if (TlsSetValue(thr_key, (LPVOID) thr) != TRUE) - croak("panic: TlsSetValue"); +#if defined(USE_ITHREADS) +# ifdef USE_DECLSPEC_THREAD + Perl_current_context = t; +# else + DWORD err = GetLastError(); + TlsSetValue(PL_thr_key,t); + SetLastError(err); +# endif +#endif } -int -thread_create(struct thread *thr, THREAD_RET_TYPE (*fn)(void *)) +void * +Perl_get_context(void) { - DWORD junk; - - MUTEX_LOCK(&thr->mutex); - self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk); - MUTEX_UNLOCK(&thr->mutex); - return self ? 0 : -1; +#if defined(USE_ITHREADS) +# ifdef USE_DECLSPEC_THREAD + return Perl_current_context; +# else + DWORD err = GetLastError(); + void *result = TlsGetValue(PL_thr_key); + SetLastError(err); + return result; +# endif +#else + return NULL; +#endif }