4 __declspec(thread) struct perl_thread *Perl_current_thread = NULL;
7 Perl_setTHR(struct perl_thread *t)
9 Perl_current_thread = t;
15 return Perl_current_thread;
19 Perl_alloc_thread_key(void)
22 static int key_allocated = 0;
24 if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
25 croak("panic: TlsAlloc");
32 Perl_set_thread_self(struct perl_thread *thr)
35 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
36 this to convert it into a handle another thread can use.
38 DuplicateHandle(GetCurrentProcess(),
44 DUPLICATE_SAME_ACCESS);
50 Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
54 MUTEX_LOCK(&thr->mutex);
55 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
56 "%p: create OS thread\n", thr));
57 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
58 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
59 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
60 MUTEX_UNLOCK(&thr->mutex);
61 return thr->self ? 0 : -1;