1 // Time-stamp: <01/08/01 21:00:29 keuchel@w2k>
6 #if defined(PERL_OBJECT)
8 extern CPerlObj* pPerl;
12 #ifdef USE_DECLSPEC_THREAD
13 __declspec(thread) void *PL_current_context = NULL;
17 Perl_set_context(void *t)
19 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
20 # ifdef USE_DECLSPEC_THREAD
21 Perl_current_context = t;
23 DWORD err = GetLastError();
24 TlsSetValue(PL_thr_key,t);
31 Perl_get_context(void)
33 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
34 # ifdef USE_DECLSPEC_THREAD
35 return Perl_current_context;
37 DWORD err = GetLastError();
38 void *result = TlsGetValue(PL_thr_key);
47 #ifdef USE_5005THREADS
49 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));
65 Perl_set_thread_self(struct perl_thread *thr)
67 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
68 this to convert it into a handle another thread can use.
70 DuplicateHandle(GetCurrentProcess(),
76 DUPLICATE_SAME_ACCESS);
80 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
85 DEBUG_S(PerlIO_printf(Perl_debug_log,
86 "%p: create OS thread\n", thr));
87 #ifdef USE_RTL_THREAD_API
88 /* See comment about USE_RTL_THREAD_API in win32thread.h */
89 #if defined(__BORLANDC__)
90 th = _beginthreadNT(fn, /* start address */
92 (void *)thr, /* parameters */
93 (void *)NULL, /* security attrib */
94 0, /* creation flags */
95 (unsigned long *)&junk); /* tid */
96 if (th == (unsigned long)-1)
98 #elif defined(_MSC_VER_)
99 th = _beginthreadex((void *)NULL, /* security attrib */
101 fn, /* start address */
102 (void*)thr, /* parameters */
103 0, /* creation flags */
104 (unsigned *)&junk); /* tid */
105 #else /* compilers using CRTDLL.DLL only have _beginthread() */
106 th = _beginthread(fn, /* start address */
108 (void*)thr); /* parameters */
109 if (th == (unsigned long)-1)
112 thr->self = (HANDLE)th;
113 #else /* !USE_RTL_THREAD_API */
114 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
115 #endif /* !USE_RTL_THREAD_API */
116 DEBUG_S(PerlIO_printf(Perl_debug_log,
117 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
118 return thr->self ? 0 : -1;