OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / include / posix-threads.h
index 1f06fc3..d5f6495 100644 (file)
@@ -19,6 +19,7 @@ details.  */
 
 #include <pthread.h>
 #include <sched.h>
+#include <sysdep/locks.h>
 
 //
 // Typedefs.
@@ -131,31 +132,7 @@ _Jv_MutexInit (_Jv_Mutex_t *mu)
   mu->owner = 0;
 }
 
-inline int
-_Jv_MutexLock (_Jv_Mutex_t *mu)
-{
-  pthread_t self = pthread_self ();
-  if (mu->owner == self)
-    {
-      mu->count++;
-    }
-  else
-    {
-#     ifdef LOCK_DEBUG
-       int result = pthread_mutex_lock (&mu->mutex);
-       if (0 != result)
-         {
-           fprintf(stderr, "Pthread_mutex_lock returned %d\n", result);
-           for (;;) {}
-         }
-#     else
-        pthread_mutex_lock (&mu->mutex);
-#     endif
-      mu->count = 1;
-      mu->owner = self;
-    }
-  return 0;
-}
+extern int _Jv_MutexLock (_Jv_Mutex_t *);
 
 inline int
 _Jv_MutexUnlock (_Jv_Mutex_t *mu)
@@ -374,4 +351,33 @@ void _Jv_ThreadWait (void);
 
 void _Jv_ThreadInterrupt (_Jv_Thread_t *data);
 
+// park() / unpark() support
+
+struct ParkHelper
+{
+  volatile obj_addr_t permit;
+  pthread_mutex_t mutex;
+  pthread_cond_t cond;
+  
+  void init ();
+  void deactivate ();
+  void destroy ();
+  void park (jboolean isAbsolute, jlong time);
+  void unpark ();
+};
+
+inline void
+ParkHelper::init ()
+{
+  pthread_mutex_init (&mutex, NULL);
+  pthread_cond_init (&cond, NULL);
+}
+
+inline void
+ParkHelper::destroy ()
+{
+  pthread_mutex_destroy (&mutex);
+  pthread_cond_destroy (&cond);
+}
+
 #endif /* __JV_POSIX_THREADS__ */