Whole document tree eh_globals.ccGo 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 <cstdlib> 00033 #include "unwind-cxx.h" 00034 #include "bits/c++config.h" 00035 #include "bits/gthr.h" 00036 00037 using namespace __cxxabiv1; 00038 00039 00040 // Single-threaded fallback buffer. 00041 static __cxa_eh_globals globals_static; 00042 00043 #if __GTHREADS 00044 static __gthread_key_t globals_key; 00045 static int use_thread_key = -1; 00046 00047 static void 00048 get_globals_dtor (void *ptr) 00049 { 00050 __gthread_key_dtor (globals_key, ptr); 00051 if (ptr) 00052 std::free (ptr); 00053 } 00054 00055 static void 00056 get_globals_init () 00057 { 00058 use_thread_key = 00059 (__gthread_key_create (&globals_key, get_globals_dtor) == 0); 00060 } 00061 00062 static void 00063 get_globals_init_once () 00064 { 00065 static __gthread_once_t once = __GTHREAD_ONCE_INIT; 00066 if (__gthread_once (&once, get_globals_init) != 0 00067 || use_thread_key < 0) 00068 use_thread_key = 0; 00069 } 00070 #endif 00071 00072 extern "C" __cxa_eh_globals * 00073 __cxa_get_globals_fast () 00074 { 00075 #if __GTHREADS 00076 if (use_thread_key) 00077 return (__cxa_eh_globals *) __gthread_getspecific (globals_key); 00078 else 00079 return &globals_static; 00080 #else 00081 return &globals_static; 00082 #endif 00083 } 00084 00085 extern "C" __cxa_eh_globals * 00086 __cxa_get_globals () 00087 { 00088 #if __GTHREADS 00089 __cxa_eh_globals *g; 00090 00091 if (use_thread_key == 0) 00092 return &globals_static; 00093 00094 if (use_thread_key < 0) 00095 { 00096 get_globals_init_once (); 00097 00098 // Make sure use_thread_key got initialized. 00099 if (use_thread_key == 0) 00100 return &globals_static; 00101 } 00102 00103 g = (__cxa_eh_globals *) __gthread_getspecific (globals_key); 00104 if (! g) 00105 { 00106 if ((g = (__cxa_eh_globals *) 00107 std::malloc (sizeof (__cxa_eh_globals))) == 0 00108 || __gthread_setspecific (globals_key, (void *) g) != 0) 00109 std::terminate (); 00110 g->caughtExceptions = 0; 00111 g->uncaughtExceptions = 0; 00112 } 00113 00114 return g; 00115 #else 00116 return &globals_static; 00117 #endif 00118 } Generated on Mon Apr 8 03:11:24 2002 for libstdc++-v3 Source by ![]() |