This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
AIX patch (including Configure support for {sched,pthread}_yield,
[perl5.git] / win32 / win32thread.c
CommitLineData
ea0efc06
MB
1#include "EXTERN.h"
2#include "perl.h"
d55594ae
GS
3
4void
5Perl_alloc_thread_key(void)
6{
7#ifdef USE_THREADS
8 static int key_allocated = 0;
9 if (!key_allocated) {
10 if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
11 croak("panic: TlsAlloc");
12 key_allocated = 1;
13 }
14#endif
15}
ea0efc06
MB
16
17void
52e1cb5e 18Perl_set_thread_self(struct perl_thread *thr)
ea0efc06 19{
d55594ae 20#ifdef USE_THREADS
4b026b9e
GS
21 /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
22 this to convert it into a handle another thread can use.
d55594ae 23 */
ea0efc06
MB
24 DuplicateHandle(GetCurrentProcess(),
25 GetCurrentThread(),
26 GetCurrentProcess(),
46930d8f 27 &thr->self,
ea0efc06
MB
28 0,
29 FALSE,
30 DUPLICATE_SAME_ACCESS);
d55594ae 31#endif
ea0efc06
MB
32}
33
d55594ae 34#ifdef USE_THREADS
ea0efc06 35int
52e1cb5e 36Perl_thread_create(struct perl_thread *thr, thread_func_t *fn)
ea0efc06
MB
37{
38 DWORD junk;
39
40 MUTEX_LOCK(&thr->mutex);
d55594ae
GS
41 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
42 "%p: create OS thread\n", thr));
46930d8f 43 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
d55594ae
GS
44 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
45 "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk));
ea0efc06 46 MUTEX_UNLOCK(&thr->mutex);
46930d8f 47 return thr->self ? 0 : -1;
ea0efc06 48}
d55594ae 49#endif