OSDN Git Service

Regenerate tree using Autoconf 2.64 and Automake 1.11.
[pf3gnuchains/gcc-fork.git] / libjava / include / posix-threads.h
index a268f1d..806ee55 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c++ -*-
 // posix-threads.h - Defines for using POSIX threads.
 
-/* Copyright (C) 1998, 1999, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2001, 2003, 2006  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -19,6 +19,7 @@ details.  */
 
 #include <pthread.h>
 #include <sched.h>
+#include <sysdep/locks.h>
 
 //
 // Typedefs.
@@ -47,7 +48,6 @@ typedef struct _Jv_Thread_t
 
 typedef void _Jv_ThreadStartFunc (java::lang::Thread *);
 
-
 // Condition Variables used to implement wait/notify/sleep/interrupt.
 typedef struct
 {
@@ -77,15 +77,29 @@ typedef struct
 // this out.  Returns 0 if the lock is held by the current thread, and
 // 1 otherwise.
 inline int
-_Jv_PthreadCheckMonitor (_Jv_Mutex_t *mu)
+_Jv_MutexCheckMonitor (_Jv_Mutex_t *mu)
+{
+  return (mu->owner != pthread_self());
+}
+
+// Type identifying a POSIX thread.
+typedef pthread_t _Jv_ThreadDesc_t;
+
+inline _Jv_ThreadDesc_t
+_Jv_GetPlatformThreadID(_Jv_Thread_t *t)
 {
-  pthread_t self = pthread_self();
-  if (mu->owner == self)
-    return 0;
-  else return 1;
+  return t->thread;
 }
 
 //
+// Signal helpers.
+//
+
+void _Jv_BlockSigchld();
+void _Jv_UnBlockSigchld();
+
+
+//
 // Condition variables.
 //
 
@@ -126,36 +140,12 @@ _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)
 {
-  if (_Jv_PthreadCheckMonitor (mu))
+  if (_Jv_MutexCheckMonitor (mu))
     {
 #     ifdef LOCK_DEBUG
        fprintf(stderr, "_Jv_MutexUnlock: Not owner\n");
@@ -221,14 +211,6 @@ _Jv_ThreadCurrent (void)
 // to threads.
 
 
-#ifdef __i386__
-
-#define SLOW_PTHREAD_SELF
-       // Add a cache for pthread_self() if we don't have the thread
-       // pointer in a register.
-
-#endif  /* __i386__ */
-
 #ifdef __ia64__
 
 typedef size_t _Jv_ThreadId_t;
@@ -252,16 +234,12 @@ _Jv_ThreadSelf (void)
 
 #ifdef __alpha__
 
-#include <asm/pal.h>
-
-typedef unsigned long _Jv_ThreadId_t;
+typedef void *_Jv_ThreadId_t;
 
 inline _Jv_ThreadId_t
 _Jv_ThreadSelf (void)
 {
-  unsigned long id;
-  __asm__ ("call_pal %1\n\tmov $0, %0" : "=r"(id) : "i"(PAL_rduniq) : "$0");
-  return id;
+  return __builtin_thread_pointer ();
 }
 
 #define JV_SELF_DEFINED
@@ -270,6 +248,8 @@ _Jv_ThreadSelf (void)
 
 #if defined(SLOW_PTHREAD_SELF)
 
+#include "sysdep/locks.h"
+
 typedef pthread_t _Jv_ThreadId_t;
 
 // E.g. on X86 Linux, pthread_self() is too slow for our purpose.
@@ -321,7 +301,7 @@ _Jv_ThreadSelf (void)
   unsigned h = SC_INDEX(sp);
   volatile self_cache_entry *sce = _Jv_self_cache + h;
   pthread_t candidate_self = sce -> self;  // Read must precede following one.
-  // Read barrier goes here, if needed.
+  read_barrier();
   if (sce -> high_sp_bits == sp >> LOG_THREAD_SPACING)
     {
       // The sce -> self value we read must be valid.  An intervening
@@ -379,4 +359,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__ */