Commit | Line | Data |
47ba8780 |
1 | |
2 | #include "EXTERN.h" |
3 | #include "perl.h" |
4 | #include "XSUB.h" |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | |
8 | #ifdef WIN32 |
9 | #include <windows.h> |
10 | #include <win32thread.h> |
82c40bf6 |
11 | #define PERL_THREAD_DETACH(t) |
7f9a95ef |
12 | #define PERL_THREAD_SETSPECIFIC(k,v) TlsSetValue(k,v) |
13 | #define PERL_THREAD_GETSPECIFIC(k,v) v = TlsGetValue(k) |
82c40bf6 |
14 | #define PERL_THREAD_ALLOC_SPECIFIC(k) \ |
15 | STMT_START {\ |
16 | if((k = TlsAlloc()) == TLS_OUT_OF_INDEXES) {\ |
17 | PerlIO_printf(PerlIO_stderr(),"panic threads.h: TlsAlloc");\ |
18 | exit(1);\ |
19 | }\ |
20 | } STMT_END |
47ba8780 |
21 | #else |
22 | #include <pthread.h> |
23 | #include <thread.h> |
82c40bf6 |
24 | |
7f9a95ef |
25 | #define PERL_THREAD_SETSPECIFIC(k,v) pthread_setspecific(k,v) |
74f0f598 |
26 | #ifdef OLD_PTHREADS_API |
27 | #define PERL_THREAD_DETACH(t) pthread_detach(&(t)) |
28 | #define PERL_THREAD_GETSPECIFIC(k,v) pthread_getspecific(k,&v) |
82c40bf6 |
29 | #define PERL_THREAD_ALLOC_SPECIFIC(k) STMT_START {\ |
74f0f598 |
30 | if(pthread_keycreate(&(k),0)) {\ |
82c40bf6 |
31 | PerlIO_printf(PerlIO_stderr(), "panic threads.h: pthread_key_create");\ |
32 | exit(1);\ |
33 | }\ |
34 | } STMT_END |
82c40bf6 |
35 | #else |
36 | #define PERL_THREAD_DETACH(t) pthread_detach((t)) |
7f9a95ef |
37 | #define PERL_THREAD_GETSPECIFIC(k,v) v = pthread_getspecific(k) |
74f0f598 |
38 | #define PERL_THREAD_ALLOC_SPECIFIC(k) STMT_START {\ |
39 | if(pthread_key_create(&(k),0)) {\ |
40 | PerlIO_printf(PerlIO_stderr(), "panic threads.h: pthread_key_create");\ |
41 | exit(1);\ |
42 | }\ |
43 | } STMT_END |
82c40bf6 |
44 | #endif |
47ba8780 |
45 | #endif |
46 | |
47 | typedef struct { |
48 | PerlInterpreter *interp; /* The threads interpreter */ |
49 | I32 tid; /* Our thread */ |
50 | perl_mutex mutex; /* our mutex */ |
51 | I32 count; /* how many threads have a reference to us */ |
52 | signed char detached; /* are we detached ? */ |
53 | SV* init_function; |
54 | SV* params; |
55 | #ifdef WIN32 |
56 | DWORD thr; |
57 | HANDLE handle; |
58 | #else |
59 | pthread_t thr; |
60 | #endif |
61 | } ithread; |
62 | |
63 | |
64 | |
65 | static perl_mutex create_mutex; /* protects the creation of threads ??? */ |
66 | |
67 | |
68 | |
69 | I32 tid_counter = 1; |
70 | shared_sv* threads; |
71 | |
82c40bf6 |
72 | perl_key self_key; |
47ba8780 |
73 | |
74 | |
75 | |
76 | |
77 | /* internal functions */ |
78 | #ifdef WIN32 |
e6e315b9 |
79 | THREAD_RET_TYPE Perl_thread_run(LPVOID arg); |
47ba8780 |
80 | #else |
e8f2bb9a |
81 | void* Perl_thread_run(void * arg); |
47ba8780 |
82 | #endif |
e6e315b9 |
83 | void Perl_thread_destruct(ithread* thread); |
47ba8780 |
84 | |
85 | /* Perl mapped functions to iThread:: */ |
e6e315b9 |
86 | SV* Perl_thread_create(char* class, SV* function_to_call, SV* params); |
87 | I32 Perl_thread_tid (SV* obj); |
88 | void Perl_thread_join(SV* obj); |
89 | void Perl_thread_detach(SV* obj); |
90 | SV* Perl_thread_self (char* class); |
47ba8780 |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |