This is the mail archive of the
java-patches@sourceware.cygnus.com
mailing list for the Java project.
Patch: yet another pthreads patch
- To: Java Patch List <java-patches@sourceware.cygnus.com>
- Subject: Patch: yet another pthreads patch
- From: Tom Tromey <tromey@cygnus.com>
- Date: 02 Sep 1999 00:23:46 -0600
- Reply-To: tromey@cygnus.com
I'm checking this in. This changes configure to check for m_count and
__m_count; the posix-threads.h change makes it so that the struct
definition of _Jv_Mutex_t will be used unless one of these is
available.
This patch also changes configure so that pthreads-related changes are
only done when pthreads are actually in use.
Bryce, can you give this a try? Thanks.
1999-09-01 Tom Tromey <tromey@cygnus.com>
* include/posix-threads.h (PTHREAD_MUTEX_IS_STRUCT): New define.
(_Jv_PthreadGetMutex): Use it.
(_Jv_PthreadCheckMonitor): Use new M_COUNT macros.
(_Jv_MutexInit): Use PTHREAD_MUTEX_IS_STRUCT.
(_Jv_MutexLock): Likewise.
(_Jv_MutexUnlock): Likewise.
* include/config.h.in: Rebuilt.
* acconfig.h (PTHREAD_MUTEX_HAVE_M_COUNT,
PTHREAD_MUTEX_HAVE___M_COUNT): New undefs.
* configure: Rebuilt.
* libgcj.spec.in: Don't mention INTERPSPEC.
* configure.in (INTERPSPEC): Removed.
Only run pthreads-related checks when using POSIX threads. Check
for m_count and __m_count in mutex structure.
Tom
Index: acconfig.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/acconfig.h,v
retrieving revision 1.7
diff -u -r1.7 acconfig.h
--- acconfig.h 1999/08/21 14:26:44 1.7
+++ acconfig.h 1999/09/02 06:19:23
@@ -106,3 +106,9 @@
/* Define if you want a bytecode interpreter. */
#undef INTERPRETER
+
+/* Define if pthread_mutex_t has m_count member. */
+#undef PTHREAD_MUTEX_HAVE_M_COUNT
+
+/* Define if pthread_mutex_t has __m_count member. */
+#undef PTHREAD_MUTEX_HAVE___M_COUNT
Index: configure.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/configure.in,v
retrieving revision 1.26
diff -u -r1.26 configure.in
--- configure.in 1999/08/21 14:26:44 1.26
+++ configure.in 1999/09/02 06:20:15
@@ -50,10 +50,6 @@
AC_DEFINE(INTERPRETER)
fi)
-dnl This becomes -lffi if the interpreter is enabled.
-INTERPSPEC=
-AC_SUBST(INTERPSPEC)
-
dnl If the target is an eCos system, use the appropriate eCos
dnl I/O routines.
dnl FIXME: this should not be a local option but a global target
@@ -306,8 +302,6 @@
GCJ=
fi
else
- # Some POSIX thread systems don't have pthread_mutexattr_settype.
- # E.g., Solaris.
AC_CHECK_FUNCS(strerror ioctl select open fsync sleep)
AC_CHECK_FUNCS(ctime_r ctime, break)
AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r)
@@ -377,23 +371,37 @@
AC_EGREP_HEADER(gethostname, unistd.h, [
AC_DEFINE(HAVE_GETHOSTNAME_DECL)])])
- # Look for these functions in the thread library.
- save_LIBS="$LIBS"
- LIBS="$LIBS $THREADLIBS"
- AC_CHECK_FUNCS(pthread_mutexattr_settype pthread_mutexattr_setkind_np)
-
- # Look for sched_yield. Up to Solaris 2.6, it is in libposix4, since
- # Solaris 7 the name librt is preferred.
- AC_CHECK_FUNCS(sched_yield, , [
- AC_CHECK_LIB(rt, sched_yield, [
- AC_DEFINE(HAVE_SCHED_YIELD)
- THREADLIBS="$THREADLIBS -lrt"
- THREADSPECS="$THREADSPECS -lrt"], [
- AC_CHECK_LIB(posix4, sched_yield, [
- AC_DEFINE(HAVE_SCHED_YIELD)
- THREADLIBS="$THREADLIBS -lposix4"
- THREADSPECS="$THREADSPECS -lposix4"])])])
- LIBS="$save_LIBS"
+ # Look for these functions in the thread library, but only bother
+ # if using POSIX threads.
+ if test "$THREADS" = posix; then
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $THREADLIBS"
+ # Some POSIX thread systems don't have pthread_mutexattr_settype.
+ # E.g., Solaris.
+ AC_CHECK_FUNCS(pthread_mutexattr_settype pthread_mutexattr_setkind_np)
+
+ # Look for sched_yield. Up to Solaris 2.6, it is in libposix4, since
+ # Solaris 7 the name librt is preferred.
+ AC_CHECK_FUNCS(sched_yield, , [
+ AC_CHECK_LIB(rt, sched_yield, [
+ AC_DEFINE(HAVE_SCHED_YIELD)
+ THREADLIBS="$THREADLIBS -lrt"
+ THREADSPECS="$THREADSPECS -lrt"], [
+ AC_CHECK_LIB(posix4, sched_yield, [
+ AC_DEFINE(HAVE_SCHED_YIELD)
+ THREADLIBS="$THREADLIBS -lposix4"
+ THREADSPECS="$THREADSPECS -lposix4"])])])
+ LIBS="$save_LIBS"
+
+ # We can save a little space at runtime if the mutex has m_count
+ # or __m_count. This is a nice hack for Linux.
+ AC_TRY_COMPILE([#include <pthread.h>], [
+ extern pthread_mutex_t *mutex; int q = mutex->m_count;
+ ], AC_DEFINE(PTHREAD_MUTEX_HAVE_M_COUNT), [
+ AC_TRY_COMPILE([#include <pthread.h>], [
+ extern pthread_mutex_t *mutex; int q = mutex->__m_count;
+ ], AC_DEFINE(PTHREAD_MUTEX_HAVE___M_COUNT))])
+ fi
# We require a way to get the time.
time_found=no
@@ -460,10 +468,6 @@
LIBS=$gcj_oldLIBS
])
SYSTEMSPEC="$SYSTEMSPEC $gcj_cv_lib_sockets"
-
- if test "$enable_interpreter" = yes; then
- INTERPSPEC=
- fi
if test "$with_system_zlib" = yes; then
AC_CHECK_LIB(z, deflate, ZLIBSPEC=-lz, ZLIBSPEC=-lzgcj)
Index: libgcj.spec.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/libgcj.spec.in,v
retrieving revision 1.4
diff -u -r1.4 libgcj.spec.in
--- libgcj.spec.in 1999/08/08 14:06:20 1.4
+++ libgcj.spec.in 1999/09/02 06:20:15
@@ -4,7 +4,7 @@
# to link with libgcj.
#
%rename lib liborig
-*lib: -lgcj -lm @INTERPSPEC@ @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(liborig)
+*lib: -lgcj -lm @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(liborig)
%rename cc1 cc1orig
*cc1: @DIVIDESPEC@ %(cc1orig)
Index: include/config.h.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/config.h.in,v
retrieving revision 1.10
diff -u -r1.10 config.h.in
--- config.h.in 1999/08/21 14:26:44 1.10
+++ config.h.in 1999/09/02 06:20:19
@@ -122,6 +122,12 @@
/* Define if you want a bytecode interpreter. */
#undef INTERPRETER
+/* Define if pthread_mutex_t has m_count member. */
+#undef PTHREAD_MUTEX_HAVE_M_COUNT
+
+/* Define if pthread_mutex_t has __m_count member. */
+#undef PTHREAD_MUTEX_HAVE___M_COUNT
+
/* Define if you have the access function. */
#undef HAVE_ACCESS
Index: include/posix-threads.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/posix-threads.h,v
retrieving revision 1.3
diff -u -r1.3 posix-threads.h
--- posix-threads.h 1999/09/01 21:03:18 1.3
+++ posix-threads.h 1999/09/02 06:20:19
@@ -31,9 +31,7 @@
typedef pthread_cond_t _Jv_ConditionVariable_t;
-// FIXME: it is ugly to use LINUX_THREADS as the define. Instead
-// think of a better scheme.
-#ifdef LINUX_THREADS
+#if defined (PTHREAD_MUTEX_HAVE_M_COUNT) || defined (PTHREAD_MUTEX_HAVE___M_COUNT)
// On Linux we use implementation details of mutexes in order to get
// faster results.
@@ -41,6 +39,8 @@
#else /* LINUX_THREADS */
+#define PTHREAD_MUTEX_IS_STRUCT
+
typedef struct
{
// Mutex used when locking this structure transiently.
@@ -67,7 +67,7 @@
int count;
} _Jv_Mutex_t;
-#endif /* LINUX_THREADS */
+#endif
typedef struct
{
@@ -88,7 +88,7 @@
inline pthread_mutex_t *
_Jv_PthreadGetMutex (_Jv_Mutex_t *mu)
{
-#if defined (LINUX_THREADS)
+#if ! defined (PTHREAD_MUTEX_IS_STRUCT)
return mu;
#elif defined (HAVE_RECURSIVE_MUTEX)
return &mu->mutex;
@@ -110,9 +110,11 @@
// See if the mutex is locked by this thread.
if (pthread_mutex_trylock (pmu))
return 1;
-#ifdef LINUX_THREADS
+#if defined (PTHREAD_MUTEX_HAVE_M_COUNT)
// On Linux we exploit knowledge of the implementation.
int r = pmu->m_count == 1;
+#elif defined (PTHREAD_MUTEX_HAVE___M_COUNT)
+ int r = pmu->__m_count == 1;
#else
int r = mu->count == 0;
#endif
@@ -170,7 +172,7 @@
_Jv_MutexInit (_Jv_Mutex_t *mu)
{
pthread_mutex_init (_Jv_PthreadGetMutex (mu), NULL);
-#ifndef LINUX_THREADS
+#ifdef PTHREAD_MUTEX_IS_STRUCT
mu->count = 0;
#endif
}
@@ -206,7 +208,7 @@
_Jv_MutexLock (_Jv_Mutex_t *mu)
{
int r = pthread_mutex_lock (mu);
-#ifndef LINUX_THREADS
+#ifdef PTHREAD_MUTEX_IS_STRUCT
if (! r)
++mu->count;
#endif
@@ -217,7 +219,7 @@
_Jv_MutexUnlock (_Jv_Mutex_t *mu)
{
int r = pthread_mutex_unlock (mu);
-#ifndef LINUX_THREADS
+#ifdef PTHREAD_MUTEX_IS_STRUCT
if (! r)
--mu->count;
#endif