win32thread.* not in MANIFEST which has muddled moving
[p5sagit/p5-mst-13.2.git] / win32 / win32thread.c
1 #include "EXTERN.h"
2 #include "perl.h"
3
4 void
5 init_thread_intern(struct thread *thr)
6 {
7 #ifdef USE_THREADS
8     static int key_allocated = 0;
9     DuplicateHandle(GetCurrentProcess(),
10                     GetCurrentThread(),
11                     GetCurrentProcess(),
12                     &thr->self,
13                     0,
14                     FALSE,
15                     DUPLICATE_SAME_ACCESS);
16     if (!key_allocated) {
17         if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
18             croak("panic: TlsAlloc");
19         key_allocated = 1;
20     }
21     if (TlsSetValue(thr_key, (LPVOID) thr) != TRUE)
22         croak("panic: TlsSetValue");
23 #endif
24 }
25
26 #ifdef USE_THREADS
27 int
28 Perl_thread_create(struct thread *thr, thread_func_t *fn)
29 {
30     DWORD junk;
31
32     MUTEX_LOCK(&thr->mutex);
33     thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
34     MUTEX_UNLOCK(&thr->mutex);
35     return thr->self ? 0 : -1;
36 }
37 #endif