Commit | Line | Data |
ea0efc06 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
d55594ae |
3 | |
4 | void |
5 | Perl_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 |
16 | |
17 | void |
18 | init_thread_intern(struct thread *thr) |
19 | { |
d55594ae |
20 | #ifdef USE_THREADS |
4b026b9e |
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 |
24 | DuplicateHandle(GetCurrentProcess(), |
25 | GetCurrentThread(), |
26 | GetCurrentProcess(), |
46930d8f |
27 | &thr->self, |
ea0efc06 |
28 | 0, |
29 | FALSE, |
30 | DUPLICATE_SAME_ACCESS); |
4b026b9e |
31 | /* XXX init thr->i here */ |
d55594ae |
32 | #endif |
ea0efc06 |
33 | } |
34 | |
d55594ae |
35 | #ifdef USE_THREADS |
ea0efc06 |
36 | int |
d55594ae |
37 | Perl_thread_create(struct thread *thr, thread_func_t *fn) |
ea0efc06 |
38 | { |
39 | DWORD junk; |
40 | |
41 | MUTEX_LOCK(&thr->mutex); |
d55594ae |
42 | DEBUG_L(PerlIO_printf(PerlIO_stderr(), |
43 | "%p: create OS thread\n", thr)); |
46930d8f |
44 | thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk); |
d55594ae |
45 | DEBUG_L(PerlIO_printf(PerlIO_stderr(), |
46 | "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk)); |
ea0efc06 |
47 | MUTEX_UNLOCK(&thr->mutex); |
46930d8f |
48 | return thr->self ? 0 : -1; |
ea0efc06 |
49 | } |
d55594ae |
50 | #endif |