4 #if defined(PERL_OBJECT)
6 extern CPerlObj* pPerl;
10 #ifdef USE_DECLSPEC_THREAD
11 __declspec(thread) struct perl_thread *Perl_current_thread = NULL;
15 Perl_setTHR(struct perl_thread *t)
18 #ifdef USE_DECLSPEC_THREAD
19 Perl_current_thread = t;
21 TlsSetValue(PL_thr_key,t);
30 #ifdef USE_DECLSPEC_THREAD
31 return Perl_current_thread;
33 return (struct perl_thread *) TlsGetValue(PL_thr_key);
41 Perl_alloc_thread_key(void)
44 static int key_allocated = 0;
46 if ((PL_thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
47 croak("panic: TlsAlloc");
54 Perl_init_thread_intern(struct perl_thread *athr)
57 #ifndef USE_DECLSPEC_THREAD
60 * Initialize port-specific per-thread data in thr->i
61 * as only things we have there are just static areas for
62 * return values we don't _need_ to do anything but
63 * this is good practice:
65 memset(&athr->i,0,sizeof(athr->i));
72 Perl_set_thread_self(struct perl_thread *thr)
75 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
76 this to convert it into a handle another thread can use.
78 DuplicateHandle(GetCurrentProcess(),
84 DUPLICATE_SAME_ACCESS);
90 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
95 DEBUG_S(PerlIO_printf(PerlIO_stderr(),
96 "%p: create OS thread\n", thr));
97 #ifdef USE_RTL_THREAD_API
98 /* See comment about USE_RTL_THREAD_API in win32thread.h */
99 #if defined(__BORLANDC__)
100 th = _beginthreadNT(fn, /* start address */
102 (void *)thr, /* parameters */
103 (void *)NULL, /* security attrib */
104 0, /* creation flags */
105 (unsigned long *)&junk); /* tid */
106 if (th == (unsigned long)-1)
108 #elif defined(_MSC_VER_)
109 th = _beginthreadex((void *)NULL, /* security attrib */
111 fn, /* start address */
112 (void*)thr, /* parameters */
113 0, /* creation flags */
114 (unsigned *)&junk); /* tid */
115 #else /* compilers using CRTDLL.DLL only have _beginthread() */
116 th = _beginthread(fn, /* start address */
118 (void*)thr); /* parameters */
119 if (th == (unsigned long)-1)
122 thr->self = (HANDLE)th;
123 #else /* !USE_RTL_THREAD_API */
124 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
125 #endif /* !USE_RTL_THREAD_API */
126 DEBUG_S(PerlIO_printf(PerlIO_stderr(),
127 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
128 return thr->self ? 0 : -1;