OLD_PTHREADS_API reorganizing.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 20 Oct 1998 15:01:20 +0000 (15:01 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 20 Oct 1998 15:01:20 +0000 (15:01 +0000)
p4raw-id: //depot/cfgperl@2028

dosish.h
ext/Thread/Thread.xs
thread.h
util.c
vmesa/vmesaish.h

index 1d52d0c..589bd56 100644 (file)
--- a/dosish.h
+++ b/dosish.h
 #    define NO_LOCALECONV_MON_THOUSANDS_SEP
 #  endif
 #  ifdef USE_THREADS
-#    define NEED_PTHREAD_INIT
 #    define OLD_PTHREADS_API
-#    define YIELD pthread_yield(NULL)
-#    define DETACH(t)                          \
-       STMT_START {                            \
-         if (pthread_detach(&(t)->self)) {     \
-             MUTEX_UNLOCK(&(t)->mutex);                \
-             croak("panic: DETACH");           \
-         }                                     \
-       } STMT_END
-#    define pthread_mutexattr_default NULL
-#    define pthread_condattr_default NULL
-#    define pthread_addr_t any_t
-#    define PTHREAD_CREATE_JOINABLE (&err)
 #  endif
 #else  /* DJGPP */
 #  ifdef WIN32
index 84f9f57..0c589a9 100644 (file)
@@ -230,9 +230,7 @@ newthread (SV *startsv, AV *initargs, char *classname)
     static int attr_inited = 0;
     sigset_t fullmask, oldmask;
 #endif
-#ifdef PTHREAD_SETDETACHSTATE_ARG2_POINTER
     static int attr_joinable = ATTR_JOINABLE;
-#endif    
 
     savethread = thr;
     thr = new_struct_thread(thr);
@@ -259,39 +257,17 @@ newthread (SV *startsv, AV *initargs, char *classname)
     err = 0;
     if (!attr_inited) {
        attr_inited = 1;
-#ifdef OLD_PTHREADS_API
-       err = pthread_attr_create(&attr);
-#else
        err = pthread_attr_init(&attr);
-#endif
-#ifdef OLD_PTHREADS_API
-#ifdef VMS
-/* This is available with the old pthreads API, but only with */
-/* DecThreads (VMS and Digital Unix (which has and uses the new one)) */
-       if (err == 0)
-           err = pthread_attr_setdetach_np(&attr, ATTR_JOINABLE);
-#endif
-#else /* !defined(VMS) */
-#ifdef ATTR_JOINABLE
+#  ifdef PTHREAD_ATTR_SETDETACHSTATE
        if (err == 0)
-           err = pthread_attr_setdetachstate(&attr, ATTR_JOINABLE);
-#else /* !defined(ATTR_JOINABLE) */
-#ifdef __UNDETACHED
-       if (err == 0)
-           err = pthread_attr_setdetachstate(&attr, &__undetached);
-#else /* !defined(__UNDETACHED) */
+           err = PTHREAD_ATTR_SETDETACHSTATE(&attr, attr_joinable);
+
+#  else
        croak("panic: can't pthread_attr_setdetachstate");
-#endif /* __UNDETACHED */
-#endif /* ATTR_JOINABLE */
-#endif /* VMS */
-#endif /* OLD_PTHREADS_API */
+#  endif
     }
     if (err == 0)
-#ifdef OLD_PTHREADS_API
-       err = pthread_create(&thr->self, attr, threadstart, (void*) thr);
-#else
-       err = pthread_create(&thr->self, &attr, threadstart, (void*) thr);
-#endif
+       err = PTHREAD_CREATE(&thr->self, attr, threadstart, (void*) thr);
     /* Go */
     MUTEX_UNLOCK(&thr->mutex);
 #endif
index 22373e6..bca5f83 100644 (file)
--- a/thread.h
+++ b/thread.h
@@ -3,14 +3,7 @@
 #ifdef WIN32
 #  include <win32thread.h>
 #else
-/* XXX What we really need is Configure probing for all of these
- * pthread thingies, old, medium, and new, not the blanket statement of
- * OLD_PTHREADS_API. --jhi */
-#  if defined(OLD_PTHREADS_API) && !defined(DJGPP) && !defined(__OPEN_VM) && !defined(OEMVS)
-     /* POSIXish threads */
-#    define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
-#    define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
-#    define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
+#  ifdef OLD_PTHREADS_API /* Here be dragons. */
 #    define DETACH(t)                          \
     STMT_START {                               \
        if (pthread_detach(&(t)->self)) {       \
            croak("panic: DETACH");             \
        }                                       \
     } STMT_END
-#  else
+#    define THR getTHR
+struct perl_thread *getTHR _((void));
+#    define PTHREAD_GETSPECIFIC_INT
+#    ifdef DJGPP
+#      define pthread_addr_t any_t
+#      define NEED_PTHREAD_INIT
+#      define PTHREAD_CREATE_JOINABLE (&err)
+#    endif
+#    ifdef __OPEN_VM
+#      define pthread_addr_t void *
+#    endif
+#    ifdef VMS
+#      define pthread_attr_init(a) pthread_attr_create(a)
+#      define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_setdetach_np(a,s)
+#      define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
+#      define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
+#    endif
+#    if defined(DJGPP) || defined(__OPEN_VM)
+#      define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,&(s))
+#      define YIELD pthread_yield(NULL)
+#    endif
+#    if defined(DJGPP) || defined(VMS)
+#      define PTHREAD_CREATE(t,a,s,d) pthread_create(t,a,s,d)
+#    endif
+#    if defined(__OPEN_VM) || defined(VMS)
+#      define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
+#    endif
+#  endif
+#  ifndef VMS
 #    define pthread_mutexattr_default NULL
-#    define pthread_condattr_default NULL
-#  endif /* OLD_PTHREADS_API */
+#    define pthread_condattr_default  NULL
+#  endif
+#endif
+
+#ifndef PTHREAD_CREATE
+/* You are not supposed to pass NULL as the 2nd arg of PTHREAD_CREATE(). */
+#  define PTHREAD_CREATE(t,a,s,d) pthread_create(t,&(a),s,d)
+#endif
+
+#ifndef PTHREAD_ATTR_SETDETACHSTATE
+#  define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,s)
 #endif
 
 #ifndef YIELD
 #endif /* SET_THR */
 
 #ifndef THR
-#  ifdef OLD_PTHREADS_API
-struct perl_thread *getTHR _((void));
-#    define THR getTHR()
-#  else
-#    define THR ((struct perl_thread *) pthread_getspecific(PL_thr_key))
-#  endif /* OLD_PTHREADS_API */
-#endif /* THR */
+#define THR ((struct perl_thread *) pthread_getspecific(PL_thr_key))
+#endif
 
 /*
  * dTHR is performance-critical. Here, we only do the pthread_get_specific
diff --git a/util.c b/util.c
index e705402..e47b95d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2767,7 +2767,7 @@ perl_cond *cp;
 }
 #endif /* FAKE_THREADS */
 
-#ifdef OLD_PTHREADS_API
+#ifdef PTHREAD_GETSPECIFIC_INT
 struct perl_thread *
 getTHR _((void))
 {
@@ -2777,7 +2777,7 @@ getTHR _((void))
        croak("panic: pthread_getspecific");
     return (struct perl_thread *) t;
 }
-#endif /* OLD_PTHREADS_API */
+#endif
 
 MAGIC *
 condpair_magic(SV *sv)
index 379d5b4..a6bd901 100644 (file)
@@ -6,11 +6,5 @@
  void * dlopen(const char *);
  void * dlsym(void *, const char *);
  void * dlerror(void);
-# ifdef YIELD
-#  undef YIELD
-# endif
-# define YIELD pthread_yield(NULL)
-# define pthread_mutexattr_default NULL
-# define pthread_condattr_default NULL
- typedef void * pthread_addr_t;
+# define OLD_PTHREADS_API
 #endif