Subject: perl5.005_02 patch for mthreads
To: perl5-porters@perl.org
Message-ID: <MLIST_Pine.GSO.4.04.
9810231410220.11111-200000@sulaco.eos.home.net>
Pthread yield probe (dejavu)
Cosmetic nanochange for the union semun output.
Better inttypes.h probe.
Undo the 'void *' $selecttype probe from #1971 because
it breaks the $selectminbits test.
p4raw-id: //depot/cfgperl@2095
# $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $
#
-# Generated on Thu Oct 22 10:24:53 EET DST 1998 [metaconfig 3.0 PL70]
+# Generated on Tue Oct 27 09:57:04 EET 1998 [metaconfig 3.0 PL70]
# (with additional metaconfig patches by jhi@iki.fi)
cat >/tmp/c1$$ <<EOF
i_inttypes=''
i_limits=''
i_locale=''
+i_machcthr=''
i_malloc=''
i_math=''
i_memory=''
eval $inlibc
: see if inttypes.h is available
-set inttypes.h i_inttypes
-eval $inhdr
+: we want a real compile instead of Inhdr because some systems
+: have an inttypes.h which includes non-existent headers
+$cat >try.c <<EOCP
+#include <inttypes.h>
+extern int foo;
+EOCP
+set try
+if eval $compile; then
+ val="$define"
+else
+ val="$undef"
+fi
+set i_inttypes
+eval $setvar
+
: check for int64_t
case "$use64bits" in
"$define" )
echo $n "Checking whether pthreads are created joinable. $c" >&4
$cat >try.c <<'EOCP'
#include <pthread.h>
+#ifdef PTHREAD_CREATE_UNDETACHED
+# define ATTR_JOINABLE PTHREAD_CREATE_UNDETACHED
+#else
+# ifdef __UNDETACHED
+# define ATTR_JOINABLE __UNDETACHED
+# endif
+#endif
#include <stdio.h>
int main() {
pthread_attr_t attr;
printf("%s\n",
pthread_attr_init(&attr) == 0 &&
#if PTHREAD_ATTR_GETDETACHSTATE_INT
- pthread_attr_getdetachstate(&attr) == 0 &&
+ pthread_attr_getdetachstate(&attr) == ATTR_JOINABLE &&
#else
pthread_attr_getdetachstate(&attr, &detachstate) == 0 &&
+ detachstate == PTHREAD_ATTR_JOINABLE
#endif
- detachstate == PTHREAD_CREATE_DETACHED ?
- "detached" : "joinable");
+ ? "detached" : "joinable");
exit(0);
}
EOCP
eval $setvar
case "$d_semctl_semid_ds" in
$define)
- echo "You can $also use struct semid_ds * for semctl IPC_STAT." >&4
+ echo "You can $also use struct semid_ds* for semctl IPC_STAT." >&4
;;
- *) echo "You cannot use struct semid_ds * for semctl IPC_STAT." >&4
+ *) echo "You cannot use struct semid_ds* for semctl IPC_STAT." >&4
;;
esac
$rm -f try.h
: The first arg can be int, unsigned, or size_t
: The last arg may or may not be 'const'
val=''
- for xxx in 'fd_set *' 'int *' 'void *'; do
+ : void pointer has been seen but using that
+ : breaks the selectminbits test
+ for xxx in 'fd_set *' 'int *'; do
for nfd in 'int' 'size_t' 'unsigned long' 'unsigned' ; do
for tmo in 'struct timeval *' 'const struct timeval *'; do
case "$val" in
set locale.h i_locale
eval $inhdr
+: see if mach cthreads are available
+set mach/cthreads.h i_machcthr
+eval $inhdr
+
: see if this is a math.h system
set math.h i_math
eval $inhdr
i_inttypes='$i_inttypes'
i_limits='$i_limits'
i_locale='$i_locale'
+i_machcthr='$i_machcthr'
i_malloc='$i_malloc'
i_math='$i_math'
i_memory='$i_memory'
*/
#$d_pthreads_created_joinable PTHREADS_CREATED_JOINABLE /**/
+/* I_MACH_CTHREADS:
+ * This symbol, if defined, indicates to the C program that it should
+ * include <mach/cthreads.h>.
+ */
+#$i_machcthr I_MACH_CTHREADS /**/
+
/* MULTIPLICITY:
* This symbol, if defined, indicates that Perl should
* be built to use multiplicity.
# include <pthread.h>
#endif
-/* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
- pthread.h must be included before all other header files.
-*/
-#if defined(USE_THREADS) && defined(PTHREAD_H_FIRST)
-# include <pthread.h>
-#endif
#ifndef _TYPES_ /* If types.h defines this it's easy. */
# ifndef major /* Does everyone's types.h define this? */
# include <sys/types.h>
# ifdef OS2
# include "os2thread.h"
# else
-# include <pthread.h>
-typedef pthread_t perl_os_thread;
-typedef pthread_mutex_t perl_mutex;
-typedef pthread_cond_t perl_cond;
-typedef pthread_key_t perl_key;
+# ifdef I_MACH_CTHREADS
+typedef cthread_t perl_os_thread;
+typedef mutex_t perl_mutex;
+typedef condition_t perl_cond;
+typedef void * perl_key;
+# else /* Posix threads */
+# include <pthread.h>
+typedef pthread_t perl_os_thread;
+typedef pthread_mutex_t perl_mutex;
+typedef pthread_cond_t perl_cond;
+typedef pthread_key_t perl_key;
+# endif /* I_MACH_CTHREADS */
# endif /* OS2 */
# endif /* WIN32 */
# endif /* FAKE_THREADS */
#endif /* USE_THREADS */
-
-
#ifdef VMS
# define STATUS_NATIVE PL_statusvalue_vms
# define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,s)
#endif
+#ifdef I_MACH_CTHREADS
+
+/* cthreads interface */
+
+/* #include <mach/cthreads.h> is in perl.h #ifdef I_MACH_CTHREADS */
+
+#define MUTEX_INIT(m) \
+ STMT_START { \
+ *m = mutex_alloc(); \
+ if (*m) { \
+ mutex_init(*m); \
+ } else { \
+ croak("panic: MUTEX_INIT"); \
+ } \
+ } STMT_END
+
+#define MUTEX_LOCK(m) mutex_lock(*m)
+#define MUTEX_UNLOCK(m) mutex_unlock(*m)
+#define MUTEX_DESTROY(m) \
+ STMT_START { \
+ mutex_free(*m); \
+ *m = 0; \
+ } STMT_END
+
+#define COND_INIT(c) \
+ STMT_START { \
+ *c = condition_alloc(); \
+ if (*c) { \
+ condition_init(*c); \
+ } else { \
+ croak("panic: COND_INIT"); \
+ } \
+ } STMT_END
+
+#define COND_SIGNAL(c) condition_signal(*c)
+#define COND_BROADCAST(c) condition_broadcast(*c)
+#define COND_WAIT(c, m) condition_wait(*c, *m)
+#define COND_DESTROY(c) \
+ STMT_START { \
+ condition_free(*c); \
+ *c = 0; \
+ } STMT_END
+
+#define THREAD_CREATE(thr, f) (thr->self = cthread_fork(f, thr), 0)
+#define THREAD_POST_CREATE(thr)
+
+#define THREAD_RET_TYPE any_t
+#define THREAD_RET_CAST(x) ((any_t) x)
+
+#define DETACH(t) cthread_detach(t->self)
+#define JOIN(t, avp) (*(avp) = (AV *)cthread_join(t->self))
+
+#define SET_THR(thr) cthread_set_data(cthread_self(), thr)
+#define THR cthread_data(cthread_self())
+
+#define INIT_THREADS cthread_init()
+#define YIELD cthread_yield()
+#define ALLOC_THREAD_KEY
+#define SET_THREAD_SELF(thr) (thr->self = cthread_self())
+
+#endif /* I_MACH_CTHREADS */
+
#ifndef YIELD
# ifdef SCHED_YIELD
# define YIELD SCHED_YIELD