1 // Time-stamp: <01/08/01 21:00:29 keuchel@w2k>
6 #ifdef USE_DECLSPEC_THREAD
7 __declspec(thread) void *PL_current_context = NULL;
11 Perl_set_context(void *t)
13 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
14 # ifdef USE_DECLSPEC_THREAD
15 Perl_current_context = t;
17 DWORD err = GetLastError();
18 TlsSetValue(PL_thr_key,t);
25 Perl_get_context(void)
27 #if defined(USE_5005THREADS) || defined(USE_ITHREADS)
28 # ifdef USE_DECLSPEC_THREAD
29 return Perl_current_context;
31 DWORD err = GetLastError();
32 void *result = TlsGetValue(PL_thr_key);
41 #ifdef USE_5005THREADS
43 Perl_init_thread_intern(struct perl_thread *athr)
45 #ifndef USE_DECLSPEC_THREAD
48 * Initialize port-specific per-thread data in thr->i
49 * as only things we have there are just static areas for
50 * return values we don't _need_ to do anything but
51 * this is good practice:
53 memset(&athr->i,0,sizeof(athr->i));
59 Perl_set_thread_self(struct perl_thread *thr)
61 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
62 this to convert it into a handle another thread can use.
64 DuplicateHandle(GetCurrentProcess(),
70 DUPLICATE_SAME_ACCESS);
74 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
79 DEBUG_S(PerlIO_printf(Perl_debug_log,
80 "%p: create OS thread\n", thr));
81 #ifdef USE_RTL_THREAD_API
82 /* See comment about USE_RTL_THREAD_API in win32thread.h */
83 #if defined(__BORLANDC__)
84 th = _beginthreadNT(fn, /* start address */
86 (void *)thr, /* parameters */
87 (void *)NULL, /* security attrib */
88 0, /* creation flags */
89 (unsigned long *)&junk); /* tid */
90 if (th == (unsigned long)-1)
92 #elif defined(_MSC_VER_)
93 th = _beginthreadex((void *)NULL, /* security attrib */
95 fn, /* start address */
96 (void*)thr, /* parameters */
97 0, /* creation flags */
98 (unsigned *)&junk); /* tid */
99 #else /* compilers using CRTDLL.DLL only have _beginthread() */
100 th = _beginthread(fn, /* start address */
102 (void*)thr); /* parameters */
103 if (th == (unsigned long)-1)
106 thr->self = (HANDLE)th;
107 #else /* !USE_RTL_THREAD_API */
108 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
109 #endif /* !USE_RTL_THREAD_API */
110 DEBUG_S(PerlIO_printf(Perl_debug_log,
111 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
112 return thr->self ? 0 : -1;