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 "unwind-cxx.h"
00033 #include "gthr.h"
00034
00035 using namespace __cxxabiv1;
00036
00037
00038
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
00101
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 }