Make Thread a wrapper for both ithreads and 5005threads.
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.h
index 869b270..72a4872 100755 (executable)
@@ -8,9 +8,40 @@
 #ifdef WIN32
 #include <windows.h>
 #include <win32thread.h>
+#define PERL_THREAD_DETACH(t) 
+#define PERL_THREAD_SETSPECIFIC(k,v) TlsSetValue(k,v)
+#define PERL_THREAD_GETSPECIFIC(k,v) v = TlsGetValue(k)
+#define PERL_THREAD_ALLOC_SPECIFIC(k) \
+STMT_START {\
+  if((k = TlsAlloc()) == TLS_OUT_OF_INDEXES) {\
+    PerlIO_printf(PerlIO_stderr(),"panic threads.h: TlsAlloc");\
+    exit(1);\
+  }\
+} STMT_END
 #else
 #include <pthread.h>
 #include <thread.h>
+
+#define PERL_THREAD_SETSPECIFIC(k,v) pthread_setspecific(k,v)
+#ifdef OLD_PTHREADS_API
+#define PERL_THREAD_DETACH(t) pthread_detach(&(t))
+#define PERL_THREAD_GETSPECIFIC(k,v) pthread_getspecific(k,&v)
+#define PERL_THREAD_ALLOC_SPECIFIC(k) STMT_START {\
+  if(pthread_keycreate(&(k),0)) {\
+    PerlIO_printf(PerlIO_stderr(), "panic threads.h: pthread_key_create");\
+    exit(1);\
+  }\
+} STMT_END
+#else
+#define PERL_THREAD_DETACH(t) pthread_detach((t))
+#define PERL_THREAD_GETSPECIFIC(k,v) v = pthread_getspecific(k)
+#define PERL_THREAD_ALLOC_SPECIFIC(k) STMT_START {\
+  if(pthread_key_create(&(k),0)) {\
+    PerlIO_printf(PerlIO_stderr(), "panic threads.h: pthread_key_create");\
+    exit(1);\
+  }\
+} STMT_END
+#endif
 #endif
 
 typedef struct {
@@ -38,25 +69,25 @@ static perl_mutex create_mutex;  /* protects the creation of threads ??? */
 I32 tid_counter = 1;
 shared_sv* threads;
 
-
+perl_key self_key;
 
 
 
 
 /* internal functions */
 #ifdef WIN32
-THREAD_RET_TYPE thread_run(LPVOID arg);
+THREAD_RET_TYPE Perl_thread_run(LPVOID arg);
 #else
-void thread_run(ithread* thread);
+void* Perl_thread_run(void * arg);
 #endif
-void thread_destruct(ithread* thread);
+void Perl_thread_destruct(ithread* thread);
 
 /* Perl mapped functions to iThread:: */
-SV* thread_create(char* class, SV* function_to_call, SV* params);
-I32 thread_tid (SV* obj);
-void thread_join(SV* obj);
-void thread_detach(SV* obj);
-SV* thread_self (char* class);
+SV* Perl_thread_create(char* class, SV* function_to_call, SV* params);
+I32 Perl_thread_tid (SV* obj);
+void Perl_thread_join(SV* obj);
+void Perl_thread_detach(SV* obj);
+SV* Perl_thread_self (char* class);