4 #ifdef USE_DECLSPEC_THREAD
5 __declspec(thread) void *PL_current_context = NULL;
9 Perl_set_context(void *t)
11 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
12 # ifdef USE_DECLSPEC_THREAD
13 Perl_current_context = t;
15 DWORD err = GetLastError();
16 TlsSetValue(PL_thr_key,t);
23 Perl_get_context(void)
25 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
26 # ifdef USE_DECLSPEC_THREAD
27 return Perl_current_context;
29 DWORD err = GetLastError();
30 void *result = TlsGetValue(PL_thr_key);
39 #ifdef USE_5005THREADS
41 Perl_init_thread_intern(struct perl_thread *athr)
43 #ifndef USE_DECLSPEC_THREAD
46 * Initialize port-specific per-thread data in thr->i
47 * as only things we have there are just static areas for
48 * return values we don't _need_ to do anything but
49 * this is good practice:
51 memset(&athr->i,0,sizeof(athr->i));
57 Perl_set_thread_self(struct perl_thread *thr)
59 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
60 this to convert it into a handle another thread can use.
62 DuplicateHandle(GetCurrentProcess(),
68 DUPLICATE_SAME_ACCESS);
72 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
77 DEBUG_S(PerlIO_printf(Perl_debug_log,
78 "%p: create OS thread\n", thr));
79 #ifdef USE_RTL_THREAD_API
80 /* See comment about USE_RTL_THREAD_API in win32thread.h */
81 #if defined(__BORLANDC__)
82 th = _beginthreadNT(fn, /* start address */
84 (void *)thr, /* parameters */
85 (void *)NULL, /* security attrib */
86 0, /* creation flags */
87 (unsigned long *)&junk); /* tid */
88 if (th == (unsigned long)-1)
90 #elif defined(_MSC_VER_)
91 th = _beginthreadex((void *)NULL, /* security attrib */
93 fn, /* start address */
94 (void*)thr, /* parameters */
95 0, /* creation flags */
96 (unsigned *)&junk); /* tid */
97 #else /* compilers using CRTDLL.DLL only have _beginthread() */
98 th = _beginthread(fn, /* start address */
100 (void*)thr); /* parameters */
101 if (th == (unsigned long)-1)
104 thr->self = (HANDLE)th;
105 #else /* !USE_RTL_THREAD_API */
106 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
107 #endif /* !USE_RTL_THREAD_API */
108 DEBUG_S(PerlIO_printf(Perl_debug_log,
109 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
110 return thr->self ? 0 : -1;