OSDN Git Service

2010-04-30 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / gthr-solaris.h
index f0d5d1e..5aed7ad 100644 (file)
@@ -1,13 +1,13 @@
 /* Threads compatibility routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997, 1999, 2000, 2004, 2005
+/* Copyright (C) 1997, 1999, 2000, 2004, 2005, 2006, 2008, 2009
    Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -15,17 +15,14 @@ WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
 
-/* As a special exception, if you link this library with other files,
-   some of which are compiled with GCC, to produce an executable,
-   this library does not by itself cause the resulting executable
-   to be covered by the GNU General Public License.
-   This exception does not however invalidate any other reasons why
-   the executable file might be covered by the GNU General Public License.  */
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
 #ifndef GCC_GTHR_SOLARIS_H
 #define GCC_GTHR_SOLARIS_H
@@ -39,6 +36,12 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include <thread.h>
 #include <errno.h>
 
+#ifdef __cplusplus
+#define UNUSED(x)
+#else
+#define UNUSED(x) x __attribute__((unused))
+#endif
+
 typedef thread_key_t __gthread_key_t;
 typedef struct {
   mutex_t mutex;
@@ -69,16 +72,17 @@ __gthrw(thr_keycreate)
 __gthrw(thr_getspecific)
 __gthrw(thr_setspecific)
 __gthrw(thr_create)
+__gthrw(thr_self)
 
+__gthrw(mutex_init)
+__gthrw(mutex_destroy)
 __gthrw(mutex_lock)
 __gthrw(mutex_trylock)
 __gthrw(mutex_unlock)
 
 #ifdef _LIBOBJC
 __gthrw(thr_exit)
-__gthrw(thr_keycreate)
 __gthrw(thr_getprio)
-__gthrw(thr_self)
 __gthrw(thr_setprio)
 __gthrw(thr_yield)
 
@@ -88,8 +92,6 @@ __gthrw(cond_wait)
 __gthrw(cond_broadcast)
 __gthrw(cond_signal)
 
-__gthrw(mutex_init)
-__gthrw(mutex_destroy)
 #endif
 
 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
@@ -100,7 +102,8 @@ __gthrw(mutex_destroy)
 static inline int
 __gthread_active_p (void)
 {
-  static void *const __gthread_active_ptr = (void *) &__gthrw_(thr_create);
+  static void *const __gthread_active_ptr
+    = __extension__ (void *) &__gthrw_(thr_create);
   return __gthread_active_ptr != 0;
 }
 
@@ -398,145 +401,155 @@ __gthread_objc_condition_signal (objc_condition_t condition)
 #else /* _LIBOBJC */
 
 static inline int
-__gthread_once (__gthread_once_t *once, void (*func) (void))
+__gthread_once (__gthread_once_t *__once, void (*__func) (void))
 {
   if (! __gthread_active_p ())
     return -1;
 
-  if (once == 0 || func == 0)
+  if (__once == 0 || __func == 0)
     return EINVAL;
 
-  if (once->once == 0)
+  if (__once->once == 0)
     {
-      int status = __gthrw_(mutex_lock) (&once->mutex);
-      if (status != 0)
-       return status;
-      if (once->once == 0)
+      int __status = __gthrw_(mutex_lock) (&__once->mutex);
+      if (__status != 0)
+       return __status;
+      if (__once->once == 0)
        {
-         (*func) ();
-         once->once++;
+         (*__func) ();
+         __once->once++;
        }
-      __gthrw_(mutex_unlock) (&once->mutex);
+      __gthrw_(mutex_unlock) (&__once->mutex);
     }
   return 0;
 }
 
 static inline int
-__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
+__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
 {
   /* Solaris 2.5 contains thr_* routines no-op in libc, so test if we actually
      got a reasonable key value, and if not, fail.  */
-  *key = (__gthread_key_t)-1;
-  if (__gthrw_(thr_keycreate) (key, dtor) != 0 || *key == (__gthread_key_t)-1)
+  *__key = (__gthread_key_t)-1;
+  if (__gthrw_(thr_keycreate) (__key, __dtor) != 0
+      || *__key == (__gthread_key_t)-1)
     return -1;
   else
     return 0;
 }
 
 static inline int
-__gthread_key_delete (__gthread_key_t key)
+__gthread_key_delete (__gthread_key_t UNUSED (__key))
 {
   /* Not possible.  */
   return -1;
 }
 
 static inline void *
-__gthread_getspecific (__gthread_key_t key)
+__gthread_getspecific (__gthread_key_t __key)
 {
-  void *ptr;
-  if (__gthrw_(thr_getspecific) (key, &ptr) == 0)
-    return ptr;
+  void *__ptr;
+  if (__gthrw_(thr_getspecific) (__key, &__ptr) == 0)
+    return __ptr;
   else
     return 0;
 }
 
 static inline int
-__gthread_setspecific (__gthread_key_t key, const void *ptr)
+__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
 {
-  return __gthrw_(thr_setspecific) (key, (void *) ptr);
+  return __gthrw_(thr_setspecific) (__key, (void *) __ptr);
 }
 
 static inline int
-__gthread_mutex_lock (__gthread_mutex_t *mutex)
+__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
-    return __gthrw_(mutex_lock) (mutex);
+    return __gthrw_(mutex_destroy) (__mutex);
   else
     return 0;
 }
 
 static inline int
-__gthread_mutex_trylock (__gthread_mutex_t *mutex)
+__gthread_mutex_lock (__gthread_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
-    return __gthrw_(mutex_trylock) (mutex);
+    return __gthrw_(mutex_lock) (__mutex);
   else
     return 0;
 }
 
 static inline int
-__gthread_mutex_unlock (__gthread_mutex_t *mutex)
+__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
-    return __gthrw_(mutex_unlock) (mutex);
+    return __gthrw_(mutex_trylock) (__mutex);
   else
     return 0;
 }
 
 static inline int
-__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
+__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
 {
-  mutex->depth = 0;
-  mutex->owner = (thread_t) 0;
-  return __gthrw_(mutex_init) (&mutex->actual, USYNC_THREAD, 0);
+  if (__gthread_active_p ())
+    return __gthrw_(mutex_unlock) (__mutex);
+  else
+    return 0;
 }
 
 static inline int
-__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
+__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
+{
+  __mutex->depth = 0;
+  __mutex->owner = (thread_t) 0;
+  return __gthrw_(mutex_init) (&__mutex->actual, USYNC_THREAD, 0);
+}
+
+static inline int
+__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
     {
-      thread_t me = __gthrw_(thr_self) ();
+      thread_t __me = __gthrw_(thr_self) ();
 
-      if (mutex->owner != me)
+      if (__mutex->owner != __me)
        {
-         __gthrw_(mutex_lock) (&mutex->actual);
-         mutex->owner = me;
+         __gthrw_(mutex_lock) (&__mutex->actual);
+         __mutex->owner = __me;
        }
 
-      mutex->depth++;
+      __mutex->depth++;
     }
   return 0;
 }
 
 static inline int
-__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
+__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
     {
-      thread_t me = __gthrw_(thr_self) ();
+      thread_t __me = __gthrw_(thr_self) ();
 
-      if (mutex->owner != me)
+      if (__mutex->owner != __me)
        {
-         if (__gthrw_(mutex_trylock) (&mutex->actual))
+         if (__gthrw_(mutex_trylock) (&__mutex->actual))
            return 1;
-         mutex->owner = me;
+         __mutex->owner = __me;
        }
 
-      mutex->depth++;
+      __mutex->depth++;
     }
   return 0;
 }
 
 static inline int
-__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
+__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
 {
   if (__gthread_active_p ())
     {
-      if (--mutex->depth == 0)
+      if (--__mutex->depth == 0)
        {
-          mutex->owner = (thread_t) 0;
-          __gthrw_(mutex_unlock) (&mutex->actual);
+          __mutex->owner = (thread_t) 0;
+          __gthrw_(mutex_unlock) (&__mutex->actual);
        }
     }
   return 0;
@@ -544,4 +557,6 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
 
 #endif /* _LIBOBJC */
 
+#undef UNUSED
+
 #endif /* ! GCC_GTHR_SOLARIS_H */