X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=win32%2Fwin32thread.c;h=1f327d6d415ec751a5a44395ad1caed6be08cd32;hb=ef469b0369ad36d7b41ff4e3416ffb34105b3bef;hp=f93d5e35850cf26eb25c3da087498d867ac4d7b3;hpb=f890e7c81bc0e52bedc3dcefbcd144d0750c257d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/win32/win32thread.c b/win32/win32thread.c index f93d5e3..1f327d6 100644 --- a/win32/win32thread.c +++ b/win32/win32thread.c @@ -1,37 +1,37 @@ #include "EXTERN.h" #include "perl.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) { -#ifdef USE_THREADS - static int key_allocated = 0; - DuplicateHandle(GetCurrentProcess(), - GetCurrentThread(), - GetCurrentProcess(), - &thr->self, - 0, - FALSE, - DUPLICATE_SAME_ACCESS); - if (!key_allocated) { - if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) - croak("panic: TlsAlloc"); - key_allocated = 1; - } - 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 } -#ifdef USE_THREADS -int -Perl_thread_create(struct thread *thr, thread_func_t *fn) +void * +Perl_get_context(void) { - DWORD junk; - - MUTEX_LOCK(&thr->mutex); - thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk); - MUTEX_UNLOCK(&thr->mutex); - return thr->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 +}