Commit | Line | Data |
ea0efc06 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
d55594ae |
3 | |
9811a7d7 |
4 | __declspec(thread) struct thread *current_thread; |
5 | |
6 | void |
7 | Perl_setTHR(struct thread *t) |
8 | { |
9 | current_thread = t; |
10 | } |
11 | |
12 | struct thread * |
13 | Perl_getTHR(void) |
14 | { |
15 | return current_thread; |
16 | } |
17 | |
d55594ae |
18 | void |
19 | Perl_alloc_thread_key(void) |
20 | { |
21 | #ifdef USE_THREADS |
22 | static int key_allocated = 0; |
23 | if (!key_allocated) { |
24 | if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) |
25 | croak("panic: TlsAlloc"); |
26 | key_allocated = 1; |
27 | } |
28 | #endif |
29 | } |
ea0efc06 |
30 | |
31 | void |
235db74f |
32 | Perl_set_thread_self(struct thread *thr) |
ea0efc06 |
33 | { |
d55594ae |
34 | #ifdef USE_THREADS |
4b026b9e |
35 | /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need |
36 | this to convert it into a handle another thread can use. |
d55594ae |
37 | */ |
ea0efc06 |
38 | DuplicateHandle(GetCurrentProcess(), |
39 | GetCurrentThread(), |
40 | GetCurrentProcess(), |
46930d8f |
41 | &thr->self, |
ea0efc06 |
42 | 0, |
43 | FALSE, |
44 | DUPLICATE_SAME_ACCESS); |
d55594ae |
45 | #endif |
ea0efc06 |
46 | } |
47 | |
d55594ae |
48 | #ifdef USE_THREADS |
ea0efc06 |
49 | int |
d55594ae |
50 | Perl_thread_create(struct thread *thr, thread_func_t *fn) |
ea0efc06 |
51 | { |
52 | DWORD junk; |
53 | |
54 | MUTEX_LOCK(&thr->mutex); |
d55594ae |
55 | DEBUG_L(PerlIO_printf(PerlIO_stderr(), |
56 | "%p: create OS thread\n", thr)); |
46930d8f |
57 | thr->self = CreateThread(NULL, 0, fn, (void*)thr, 0, &junk); |
d55594ae |
58 | DEBUG_L(PerlIO_printf(PerlIO_stderr(), |
59 | "%p: OS thread = %p, id=%ld\n", thr, thr->self, junk)); |
ea0efc06 |
60 | MUTEX_UNLOCK(&thr->mutex); |
46930d8f |
61 | return thr->self ? 0 : -1; |
ea0efc06 |
62 | } |
d55594ae |
63 | #endif |