X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=win32%2Fwin32thread.c;h=1f327d6d415ec751a5a44395ad1caed6be08cd32;hb=f3c90b3644a4d1b01ee1a6fe678bc1357e85a56a;hp=e74d7e8933ec1edf7dad9761d0c67548112dd520;hpb=ea0efc06fdad2019ffceb86d079dd853e9d79cea;p=p5sagit%2Fp5-mst-13.2.git 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 }