X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=thread.h;h=a82c01b61d07d625e519297cea73a07658300829;hb=7efe98a674232612e623f7ff1b0bf033662f21d3;hp=f7ab18c553c4600b78374f92cc3d8db97fc494ff;hpb=631cfb58c2bd693774ee9ffe59908af4423167d4;p=p5sagit%2Fp5-mst-13.2.git diff --git a/thread.h b/thread.h index f7ab18c..a82c01b 100644 --- a/thread.h +++ b/thread.h @@ -1,8 +1,15 @@ #if defined(USE_THREADS) || defined(USE_ITHREADS) +#if defined(VMS) +#include +#endif + #ifdef WIN32 # include #else +#ifdef NETWARE +# include +#else # ifdef OLD_PTHREADS_API /* Here be dragons. */ # define DETACH(t) \ STMT_START { \ @@ -32,13 +39,25 @@ # define pthread_mutexattr_init(a) pthread_mutexattr_create(a) # define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t) # endif +# if defined(__hpux) && defined(__ux_version) && __ux_version <= 1020 +# define pthread_attr_init(a) pthread_attr_create(a) + /* XXX pthread_setdetach_np() missing in DCE threads on HP-UX 10.20 */ +# define PTHREAD_ATTR_SETDETACHSTATE(a,s) (0) +# define PTHREAD_CREATE(t,a,s,d) pthread_create(t,a,s,d) +# define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d)) +# define pthread_mutexattr_init(a) pthread_mutexattr_create(a) +# define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t) +# endif # if defined(DJGPP) || defined(__OPEN_VM) # define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,&(s)) # define YIELD pthread_yield(NULL) # endif # endif +# if !defined(__hpux) || !defined(__ux_version) || __ux_version > 1020 # define pthread_mutexattr_default NULL # define pthread_condattr_default NULL +# endif +#endif /* NETWARE */ #endif #ifndef PTHREAD_CREATE @@ -58,6 +77,10 @@ # endif #endif +#ifdef DGUX +# define THREAD_CREATE_NEEDS_STACK (16*1024) +#endif + #ifdef I_MACH_CTHREADS /* cthreads interface */ @@ -117,6 +140,7 @@ #define INIT_THREADS cthread_init() #define YIELD cthread_yield() #define ALLOC_THREAD_KEY NOOP +#define FREE_THREAD_KEY NOOP #define SET_THREAD_SELF(thr) (thr->self = cthread_self()) #endif /* I_MACH_CTHREADS */ @@ -229,8 +253,22 @@ } STMT_END #endif /* JOIN */ +/* Use an unchecked fetch of thread-specific data instead of a checked one. + * It would fail if the key were bogus, but if the key were bogus then + * Really Bad Things would be happening anyway. --dan */ +#if (defined(__ALPHA) && (__VMS_VER >= 70000000)) || \ + (defined(__alpha) && defined(__osf__)) /* Available only on >= 4.0 */ +# define HAS_PTHREAD_UNCHECKED_GETSPECIFIC_NP /* Configure test needed */ +#endif + +#ifdef HAS_PTHREAD_UNCHECKED_GETSPECIFIC_NP +# define PTHREAD_GETSPECIFIC(key) pthread_unchecked_getspecific_np(key) +#else +# define PTHREAD_GETSPECIFIC(key) pthread_getspecific(key) +#endif + #ifndef PERL_GET_CONTEXT -# define PERL_GET_CONTEXT pthread_getspecific(PL_thr_key) +# define PERL_GET_CONTEXT PTHREAD_GETSPECIFIC(PL_thr_key) #endif #ifndef PERL_SET_CONTEXT @@ -251,12 +289,37 @@ # define ALLOC_THREAD_KEY \ STMT_START { \ if (pthread_key_create(&PL_thr_key, 0)) { \ - fprintf(stderr, "panic: pthread_key_create"); \ + PerlIO_printf(PerlIO_stderr(), "panic: pthread_key_create"); \ exit(1); \ } \ } STMT_END #endif +#ifndef FREE_THREAD_KEY +# define FREE_THREAD_KEY \ + STMT_START { \ + pthread_key_delete(PL_thr_key); \ + } STMT_END +#endif + +void Perl_atfork_lock(void); +void Perl_atfork_unlock(void); + +#ifndef PTHREAD_ATFORK +# ifdef HAS_PTHREAD_ATFORK +# define PTHREAD_ATFORK(prepare,parent,child) \ + pthread_atfork(prepare,parent,child) +# else +# ifdef HAS_FORK +# define PTHREAD_ATFORK(prepare,parent,child) \ + Perl_croak(aTHX_ "No pthread_atfork() -- fork() too unsafe"); +# else +# define PTHREAD_ATFORK(prepare,parent,child) \ + NOOP +# endif +# endif +#endif + #ifndef THREAD_RET_TYPE # define THREAD_RET_TYPE void * # define THREAD_RET_CAST(p) ((void *)(p)) @@ -411,3 +474,7 @@ typedef struct condpair { #ifndef INIT_THREADS # define INIT_THREADS NOOP #endif + +#ifndef PTHREAD_ATFORK +# define PTHREAD_ATFORK(prepare,parent,child) NOOP +#endif