00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
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
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 }