This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate latest mainline into win32 branch.
[perl5.git] / win32 / win32thread.c
CommitLineData
ea0efc06
MB
1#include "EXTERN.h"
2#include "perl.h"
3#include "win32/win32thread.h"
4
5void
6init_thread_intern(struct thread *thr)
7{
8 DuplicateHandle(GetCurrentProcess(),
9 GetCurrentThread(),
10 GetCurrentProcess(),
46930d8f 11 &thr->self,
ea0efc06
MB
12 0,
13 FALSE,
14 DUPLICATE_SAME_ACCESS);
15 if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
16 croak("panic: TlsAlloc");
17 if (TlsSetValue(thr_key, (LPVOID) thr) != TRUE)
18 croak("panic: TlsSetValue");
19}
20
21int
22thread_create(struct thread *thr, THREAD_RET_TYPE (*fn)(void *))
23{
24 DWORD junk;
25
26 MUTEX_LOCK(&thr->mutex);
46930d8f 27 thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
ea0efc06 28 MUTEX_UNLOCK(&thr->mutex);
46930d8f 29 return thr->self ? 0 : -1;
ea0efc06 30}