aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>1999-09-01 18:29:39 +0000
committerTom Tromey <tromey@cygnus.com>1999-09-01 18:29:39 +0000
commit65bc77d47bebb09c5c9ad7ca8b4780c8b7bc18c9 (patch)
tree6fb15ec8b692fb14a98a2eaba9879e17e7f496a6
parentd22ddc6d19e80f6e79f1b6d08f7f9d0af39f09aa (diff)
* posix-threads.cc (_Jv_CondWait): Call _Jv_PthreadCheckMonitor.
* include/posix-threads.h (_Jv_PthreadCheckMonitor): New function. (_Jv_CondNotify): Use it. (_Jv_CondNotifyAll): Likewise. * java/lang/Class.h (JV_STATE_NOTHING): Correct misspelling. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@29030 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/include/posix-threads.h29
-rw-r--r--libjava/java/lang/Class.h2
-rw-r--r--libjava/java/lang/natClassLoader.cc2
-rw-r--r--libjava/posix-threads.cc5
5 files changed, 40 insertions, 8 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index dd5e2f9ce79..5a6d8a80b0a 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+1999-09-01 Tom Tromey <tromey@cygnus.com>
+
+ * posix-threads.cc (_Jv_CondWait): Call _Jv_PthreadCheckMonitor.
+ * include/posix-threads.h (_Jv_PthreadCheckMonitor): New
+ function.
+ (_Jv_CondNotify): Use it.
+ (_Jv_CondNotifyAll): Likewise.
+
+ * java/lang/Class.h (JV_STATE_NOTHING): Correct misspelling.
+
1999-08-31 Tom Tromey <tromey@cygnus.com>
* include/jvm.h (_Jv_makeUtf8TypeConst): Removed unused
diff --git a/libjava/include/posix-threads.h b/libjava/include/posix-threads.h
index 6e4cc70c020..2ad6c06e047 100644
--- a/libjava/include/posix-threads.h
+++ b/libjava/include/posix-threads.h
@@ -65,6 +65,25 @@ typedef struct
typedef void _Jv_ThreadStartFunc (java::lang::Thread *);
+// This is a convenience function used only by the pthreads thread
+// implementation. This is slow, but that's too bad -- we need to do
+// the checks for correctness. It might be nice to be able to compile
+// this out.
+inline int _Jv_PthreadCheckMonitor (_Jv_Mutex_t *mu)
+{
+ pthread_mutex_t *pmu;
+#ifdef HAVE_RECURSIVE_MUTEX
+ pmu = mu;
+#else
+ pmu = &mu->mutex2;
+#endif
+ // See if the mutex is locked by this thread.
+ if (pthread_mutex_trylock (pmu))
+ return 1;
+ pthread_mutex_unlock (pmu);
+ return 0;
+}
+
//
// Condition variables.
//
@@ -94,17 +113,15 @@ int _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
jlong millis, jint nanos);
inline int
-_Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *)
+_Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu)
{
- // FIXME: check to see if mutex is held by current thread.
- return pthread_cond_signal (cv);
+ return _Jv_PthreadCheckMonitor (mu) || pthread_cond_signal (cv);
}
inline int
-_Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *)
+_Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu)
{
- // FIXME: check to see if mutex is held by current thread.
- return pthread_cond_broadcast (cv);
+ return _Jv_PthreadCheckMonitor (mu) || pthread_cond_broadcast (cv);
}
diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h
index b038c349826..fd2c2eba777 100644
--- a/libjava/java/lang/Class.h
+++ b/libjava/java/lang/Class.h
@@ -27,7 +27,7 @@ extern "C" void _Jv_RegisterClasses (jclass *classes);
// `resolved' must come between `nothing' and the other states.
// Whenever the state changes, one should notify all waiters of this
// class.
-#define JV_STATE_NOTING 0 // set by compiler
+#define JV_STATE_NOTHING 0 // set by compiler
#define JV_STATE_PRELOADING 1 // can do _Jv_FindClass
#define JV_STATE_LOADING 3 // has super installed
diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc
index 28a70e7b7e4..0bd7cd0d9e9 100644
--- a/libjava/java/lang/natClassLoader.cc
+++ b/libjava/java/lang/natClassLoader.cc
@@ -405,7 +405,7 @@ _Jv_RegisterClasses (jclass *classes)
// registering a compiled class causes
// it to be immediately "prepared".
- if (klass->state == JV_STATE_NOTING)
+ if (klass->state == JV_STATE_NOTHING)
klass->state = JV_STATE_COMPILED;
}
}
diff --git a/libjava/posix-threads.cc b/libjava/posix-threads.cc
index 48f0a7f738f..413f7c3bfce 100644
--- a/libjava/posix-threads.cc
+++ b/libjava/posix-threads.cc
@@ -75,6 +75,9 @@ int
_Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
jlong millis, jint nanos)
{
+ if (_Jv_PthreadCheckMonitor (mu))
+ return 1;
+
int r;
pthread_mutex_t *pmu;
#ifdef HAVE_RECURSIVE_MUTEX
@@ -82,6 +85,7 @@ _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
#else
pmu = &mu->mutex2;
#endif
+
if (millis == 0 && nanos == 0)
r = pthread_cond_wait (cv, pmu);
else
@@ -96,6 +100,7 @@ _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
if (r && errno == ETIMEDOUT)
r = 0;
}
+
return r;
}