4 #ifdef USE_DECLSPEC_THREAD
5 __declspec(thread) struct perl_thread *Perl_current_thread = NULL;
9 Perl_setTHR(struct perl_thread *t)
12 #ifdef USE_DECLSPEC_THREAD
13 Perl_current_thread = t;
15 TlsSetValue(thr_key,t);
24 #ifdef USE_DECLSPEC_THREAD
25 return Perl_current_thread;
27 return (struct perl_thread *) TlsGetValue(thr_key);
35 Perl_alloc_thread_key(void)
38 static int key_allocated = 0;
40 if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
41 croak("panic: TlsAlloc");
48 Perl_init_thread_intern(struct perl_thread *athr)
51 #ifndef USE_DECLSPEC_THREAD
54 * Initialize port-specific per-thread data in thr->i
55 * as only things we have there are just static areas for
56 * return values we don't _need_ to do anything but
57 * this is good practice:
59 memset(&athr->i,0,sizeof(athr->i));
66 Perl_set_thread_self(struct perl_thread *thr)
69 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
70 this to convert it into a handle another thread can use.
72 DuplicateHandle(GetCurrentProcess(),
78 DUPLICATE_SAME_ACCESS);
84 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
89 MUTEX_LOCK(&thr->mutex);
90 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
91 "%p: create OS thread\n", thr));
92 #ifdef USE_RTL_THREAD_API
93 /* See comment about USE_RTL_THREAD_API in win32thread.h */
94 #if defined(__BORLANDC__)
95 th = _beginthreadNT(fn, /* start address */
97 (void *)thr, /* parameters */
98 (void *)NULL, /* security attrib */
99 0, /* creation flags */
100 (unsigned long *)&junk); /* tid */
101 if (th == (unsigned long)-1)
103 #elif defined(_MSC_VER_)
104 th = _beginthreadex((void *)NULL, /* security attrib */
106 fn, /* start address */
107 (void*)thr, /* parameters */
108 0, /* creation flags */
109 (unsigned *)&junk); /* tid */
110 #else /* compilers using CRTDLL.DLL only have _beginthread() */
111 th = _beginthread(fn, /* start address */
113 (void*)thr); /* parameters */
114 if (th == (unsigned long)-1)
117 thr->self = (HANDLE)th;
118 #else /* !USE_RTL_THREAD_API */
119 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
120 #endif /* !USE_RTL_THREAD_API */
121 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
122 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
123 MUTEX_UNLOCK(&thr->mutex);
124 return thr->self ? 0 : -1;