Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

eh_globals.cc

Go to the documentation of this file.
00001 // -*- C++ -*- Manage the thread-local exception globals.
00002 // Copyright (C) 2001 Free Software Foundation, Inc.
00003 //
00004 // This file is part of GNU CC.
00005 //
00006 // GNU CC is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 //
00011 // GNU CC is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with GNU CC; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330,
00019 // Boston, MA 02111-1307, USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 
00031 #include <exception>
00032 #include "unwind-cxx.h"
00033 #include "gthr.h"
00034 
00035 using namespace __cxxabiv1;
00036 
00037 
00038 // Single-threaded fallback buffer.
00039 static __cxa_eh_globals globals_static;
00040 
00041 #if __GTHREADS
00042 static __gthread_key_t globals_key;
00043 static int use_thread_key = -1;
00044 
00045 static void
00046 get_globals_dtor (void *ptr)
00047 {
00048   __gthread_key_dtor (globals_key, ptr);
00049   if (ptr)
00050     free (ptr);
00051 }
00052 
00053 static void
00054 get_globals_init ()
00055 {
00056   use_thread_key =
00057     (__gthread_key_create (&globals_key, get_globals_dtor) == 0);
00058 }
00059 
00060 static void
00061 get_globals_init_once ()
00062 {
00063   static __gthread_once_t once = __GTHREAD_ONCE_INIT;
00064   if (__gthread_once (&once, get_globals_init) != 0
00065       || use_thread_key < 0)
00066     use_thread_key = 0;
00067 }
00068 #endif
00069 
00070 extern "C" __cxa_eh_globals *
00071 __cxa_get_globals_fast ()
00072 {
00073 #if __GTHREADS
00074   if (use_thread_key)
00075     return (__cxa_eh_globals *) __gthread_getspecific (globals_key);
00076   else
00077     return &globals_static;
00078 #else
00079   return &globals_static;
00080 #endif
00081 }
00082 
00083 extern "C" __cxa_eh_globals *
00084 __cxa_get_globals ()
00085 {
00086 #if __GTHREADS
00087   __cxa_eh_globals *g;
00088 
00089   if (use_thread_key == 0)
00090     return &globals_static;
00091 
00092   if (use_thread_key < 0)
00093     get_globals_init_once ();
00094 
00095   g = (__cxa_eh_globals *) __gthread_getspecific (globals_key);
00096   if (! g)
00097     {
00098       static __gthread_once_t once = __GTHREAD_ONCE_INIT;
00099 
00100       // Make sure use_thread_key got initialized.  Some systems have
00101       // dummy thread routines in their libc that return a success.
00102       if (__gthread_once (&once, eh_threads_initialize) != 0
00103       || use_thread_key < 0)
00104     {
00105       use_thread_key = 0;
00106       return &globals_static;
00107     }
00108       
00109       if ((g = malloc (sizeof (__cxa_eh_globals))) == 0
00110       || __gthread_setspecific (eh_context_key, (void *) g) != 0)
00111         std::terminate ();
00112       g->caughtExceptions = 0;
00113       g->uncaughtExceptions = 0;
00114     }
00115 
00116   return g;
00117 #else
00118   return &globals_static;
00119 #endif
00120 }

Generated at Tue May 1 16:28:37 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001