4 #if defined(PERL_OBJECT)
6 extern CPerlObj* pPerl;
10 #ifdef USE_DECLSPEC_THREAD
11 __declspec(thread) void *PL_current_context = NULL;
15 Perl_set_context(void *t)
17 #if defined(USE_THREADS) || defined(USE_ITHREADS)
18 # ifdef USE_DECLSPEC_THREAD
19 Perl_current_context = t;
21 DWORD err = GetLastError();
22 TlsSetValue(PL_thr_key,t);
29 Perl_get_context(void)
31 #if defined(USE_THREADS) || defined(USE_ITHREADS)
32 # ifdef USE_DECLSPEC_THREAD
33 return Perl_current_context;
35 DWORD err = GetLastError();
36 void *result = TlsGetValue(PL_thr_key);
47 Perl_init_thread_intern(struct perl_thread *athr)
49 #ifndef USE_DECLSPEC_THREAD
52 * Initialize port-specific per-thread data in thr->i
53 * as only things we have there are just static areas for
54 * return values we don't _need_ to do anything but
55 * this is good practice:
57 memset(&athr->i,0,sizeof(athr->i));
63 Perl_set_thread_self(struct perl_thread *thr)
65 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
66 this to convert it into a handle another thread can use.
68 DuplicateHandle(GetCurrentProcess(),
74 DUPLICATE_SAME_ACCESS);
78 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
83 DEBUG_S(PerlIO_printf(Perl_debug_log,
84 "%p: create OS thread\n", thr));
85 #ifdef USE_RTL_THREAD_API
86 /* See comment about USE_RTL_THREAD_API in win32thread.h */
87 #if defined(__BORLANDC__)
88 th = _beginthreadNT(fn, /* start address */
90 (void *)thr, /* parameters */
91 (void *)NULL, /* security attrib */
92 0, /* creation flags */
93 (unsigned long *)&junk); /* tid */
94 if (th == (unsigned long)-1)
96 #elif defined(_MSC_VER_)
97 th = _beginthreadex((void *)NULL, /* security attrib */
99 fn, /* start address */
100 (void*)thr, /* parameters */
101 0, /* creation flags */
102 (unsigned *)&junk); /* tid */
103 #else /* compilers using CRTDLL.DLL only have _beginthread() */
104 th = _beginthread(fn, /* start address */
106 (void*)thr); /* parameters */
107 if (th == (unsigned long)-1)
110 thr->self = (HANDLE)th;
111 #else /* !USE_RTL_THREAD_API */
112 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
113 #endif /* !USE_RTL_THREAD_API */
114 DEBUG_S(PerlIO_printf(Perl_debug_log,
115 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
116 return thr->self ? 0 : -1;