This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Improve internal threading API. Introduce win32/win32thread.[ch]
[perl5.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                     &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     self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk);
28     MUTEX_UNLOCK(&thr->mutex);
29     return self ? 0 : -1;
30 }