From 5377b9f6af77be3383c8741f3fb16d5924624e79 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Sat, 1 Feb 1997 03:56:08 +0100
Subject: [PATCH] Some more thread-support.

Rev: src/acconfig.h:1.4
Rev: src/configure.in:1.55
Rev: src/threads.h:1.9
---
 src/acconfig.h   |  3 +++
 src/configure.in | 34 ++++++++++++++++++++++++++--
 src/threads.h    | 59 ++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 89 insertions(+), 7 deletions(-)

diff --git a/src/acconfig.h b/src/acconfig.h
index 0f41075c6e..c67f0e9eba 100644
--- a/src/acconfig.h
+++ b/src/acconfig.h
@@ -130,6 +130,9 @@
 #undef _SGI_SPROC_THREADS
 #undef _SGI_MP_SOURCE
 
+/* Define this if your pthreads have pthread_condattr_default */
+#undef HAVE_PTHREAD_CONDATTR_DEFAULT
+
 @BOTTOM@
 
 /* How to set a socket non-blocking */
diff --git a/src/configure.in b/src/configure.in
index 947574d468..330c10ef38 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.54 1997/01/31 23:46:11 hubbe Exp $")
+AC_REVISION("$Id: configure.in,v 1.55 1997/02/01 02:56:07 grubba Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -512,7 +512,37 @@ int main()
       AC_DEFINE(_REENTRANT)
       AC_DEFINE(_THREAD_SAFE)
       AC_DEFINE(_MIT_POSIX_THREADS)
-      AC_CHECK_FUNCS(pthread_attr_setstacksize)
+      AC_CHECK_FUNCS(pthread_attr_setstacksize pthread_yield \
+		     pthread_cond_init)
+      AC_MSG_CHECKING(if pthread_condattr_default is defined)
+      AC_CACHE_VAL(pike_cv_have_pthread_condattr_default,[
+        AC_TRY_COMPILE([
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif /* HAVE_PTHREAD_H */
+void foo(pthread_cond_t *bar)
+{
+  pthread_cond_init(bar, pthread_condattr_default)
+}
+
+int main(int argc, char **argv)
+{
+  exit(0);
+}
+        ],[
+	  pike_cv_have_pthread_condattr_default=yes
+	],[
+	  pike_cv_have_pthread_condattr_default=no
+	])
+      ])
+
+      AC_MSG_RESULT($pike_cv_have_pthread_condattr_default)
+
+      if test x$pike_cv_have_pthread_condattr_default = xyes ; then
+        AC_DEFINE(HAVE_PTHREAD_CONDATTR_DEFAULT)
+      else
+        :
+      fi
     else
       AC_MSG_RESULT(no)
       LIBS="$OLDLIBS"
diff --git a/src/threads.h b/src/threads.h
index 6e355f07a2..adeb083b8f 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -20,6 +20,11 @@
 #undef HAVE_PTHREAD_H
 #endif
 
+#ifdef SPROC_THREADS
+/* Not supported yet */
+#undef SPROC_THREADS
+#undef HAVE_SPROC
+#endif /* SPROC_THREADS */
 
 
 extern int num_threads;
@@ -44,20 +49,34 @@ extern struct object *thread_id;
  * threaded.
  */
 #define th_setconcurrency(X) 
+#ifdef HAVE_PTHREAD_YIELD
+#define th_yield()	pthread_yield()
+#else
 #define th_yield()
-
+#endif /* HAVE_PTHREAD_YIELD */
 
 #define th_create(ID,fun,arg) pthread_create(ID,&pattr,fun,arg)
 #define th_exit(foo) pthread_exit(foo)
 #define th_self() pthread_self()
 
+#ifdef HAVE_PTHREAD_COND_INIT
 #define COND_T pthread_cond_t
+
+#ifdef HAVE_PTHREAD_CONDATTR_DEFAULT
+#define co_init(X) pthread_cond_init((X), pthread_condattr_default)
+#else
 #define co_init(X) pthread_cond_init((X), 0)
+#endif /* HAVE_PTHREAD_CONDATTR_DEFAULT */
+
 #define co_wait(COND, MUTEX) pthread_cond_wait((COND), (MUTEX))
 #define co_signal(X) pthread_cond_signal(X)
 #define co_broadcast(X) pthread_cond_broadcast(X)
 #define co_destroy(X) pthread_cond_destroy(X)
-#endif
+#else
+#error No way to make cond-vars
+#endif /* HAVE_PTHREAD_COND_INIT */
+
+#endif /* POSIX_THREADS */
 
 
 
@@ -85,7 +104,36 @@ extern struct object *thread_id;
 #define co_signal(X) cond_signal(X)
 #define co_broadcast(X) cond_broadcast(X)
 #define co_destroy(X) cond_destroy(X)
-#endif
+
+
+#endif /* UNIX_THREADS */
+
+#ifdef SPROC_THREADS
+
+/*
+ * Not fully supported yet
+ */
+#define THREAD_T	int
+
+#define MUTEX_T		ulock_t
+#define mt_init(X)	(usinitlock(((*X) = usnewlock(/*********/))))
+#define mt_lock(X)	ussetlock(*X)
+#define mt_unlock(X)	usunsetlock(*X)
+#define mt_destroy(X)	usfreelock((*X), /*******/)
+
+#define th_setconcurrency(X)	/*******/
+
+#define PIKE_SPROC_FLAGS	(PR_SADDR|PR_SFDS|PR_SDIR|PS_SETEXITSIG)
+#define th_create(ID, fun, arg)	(((*(ID)) = sproc(fun, PIKE_SPROC_FLAGS, arg)) == -1)
+#define th_exit(X)	exit(X)
+#define th_self()	getpid()
+#define th_yield()	sginap(0)
+
+/*
+ * No cond_vars yet
+ */
+
+#endif /* SPROC_THREADS */
 
 extern MUTEX_T interpreter_lock;
 
@@ -173,8 +221,9 @@ void th_cleanup();
 #define th_init()
 #define th_cleanup()
 #define th_init_programs()
-#endif
+#endif /* _REENTRANT */
 
 
 extern int threads_disabled;
-#endif
+
+#endif /* THREADS_H */
-- 
GitLab