9f63d178f4c64fcfa9cbd9ed18f7e91efee966ec
[p5sagit/p5-mst-13.2.git] / win32 / win32thread.c
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "win32/win32thread.h"
4
5 void
6 init_thread_intern(struct thread *thr)
7 {
8     DuplicateHandle(GetCurrentProcess(),
9                     GetCurrentThread(),
10                     GetCurrentProcess(),
11                     &thr->self,
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
21 int
22 thread_create(struct thread *thr, THREAD_RET_TYPE (*fn)(void *))
23 {
24     DWORD junk;
25
26     MUTEX_LOCK(&thr->mutex);
27     thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
28     MUTEX_UNLOCK(&thr->mutex);
29     return thr->self ? 0 : -1;
30 }