This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX.pod: Various nits, typos, clarifications
[perl5.git] / win32 / win32thread.c
index e74d7e8..1f327d6 100644 (file)
@@ -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
 }