OSDN Git Service

2004-04-06 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / eh_globals.cc
index a247b84..4276022 100644 (file)
@@ -1,20 +1,20 @@
 // -*- C++ -*- Manage the thread-local exception globals.
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
 //
-// This file is part of GNU CC.
+// This file is part of GCC.
 //
-// GNU CC is free software; you can redistribute it and/or modify
+// 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 version.
 //
-// GNU CC is distributed in the hope that it will be useful,
+// GCC is distributed in the hope that it will be useful,
 // but WITHOUT ANY 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 GNU CC; see the file COPYING.  If not, write to
+// along with GCC; see the file COPYING.  If not, write to
 // the Free Software Foundation, 59 Temple Place - Suite 330,
 // Boston, MA 02111-1307, USA.
 
 
 
 #include <exception>
+#include <cstdlib>
 #include "unwind-cxx.h"
-#include "gthr.h"
+#include "bits/c++config.h"
+#include "bits/gthr.h"
 
 using namespace __cxxabiv1;
 
@@ -45,9 +47,8 @@ static int use_thread_key = -1;
 static void
 get_globals_dtor (void *ptr)
 {
-  __gthread_key_dtor (globals_key, ptr);
   if (ptr)
-    free (ptr);
+    std::free (ptr);
 }
 
 static void
@@ -68,7 +69,7 @@ get_globals_init_once ()
 #endif
 
 extern "C" __cxa_eh_globals *
-__cxa_get_globals_fast ()
+__cxa_get_globals_fast () throw()
 {
 #if __GTHREADS
   if (use_thread_key)
@@ -81,7 +82,7 @@ __cxa_get_globals_fast ()
 }
 
 extern "C" __cxa_eh_globals *
-__cxa_get_globals ()
+__cxa_get_globals () throw()
 {
 #if __GTHREADS
   __cxa_eh_globals *g;
@@ -90,24 +91,20 @@ __cxa_get_globals ()
     return &globals_static;
 
   if (use_thread_key < 0)
-    get_globals_init_once ();
+    {
+      get_globals_init_once ();
+
+      // Make sure use_thread_key got initialized.
+      if (use_thread_key == 0)
+       return &globals_static;
+    }
 
   g = (__cxa_eh_globals *) __gthread_getspecific (globals_key);
   if (! g)
     {
-      static __gthread_once_t once = __GTHREAD_ONCE_INIT;
-
-      // Make sure use_thread_key got initialized.  Some systems have
-      // dummy thread routines in their libc that return a success.
-      if (__gthread_once (&once, eh_threads_initialize) != 0
-         || use_thread_key < 0)
-       {
-         use_thread_key = 0;
-         return &globals_static;
-       }
-      
-      if ((g = malloc (sizeof (__cxa_eh_globals))) == 0
-         || __gthread_setspecific (eh_context_key, (void *) g) != 0)
+      if ((g = (__cxa_eh_globals *)
+          std::malloc (sizeof (__cxa_eh_globals))) == 0
+         || __gthread_setspecific (globals_key, (void *) g) != 0)
         std::terminate ();
       g->caughtExceptions = 0;
       g->uncaughtExceptions = 0;