2121#include < NdbTick.h>
2222#include < NdbCondition.h>
2323#include < NdbSleep.h>
24- #include < my_pthread.h>
2524
2625static NdbTableImpl * f_invalid_table = 0 ;
2726static NdbTableImpl * f_altered_table = 0 ;
2827
28+ // If we are linked with libstdc++ then thread safe
29+ // initialization of the shared table objects can be simplified
30+ #if HAVE_CXXABI_H
31+ #include < my_pthread.h>
32+
2933static my_pthread_once_t once_control = MY_PTHREAD_ONCE_INIT;
3034
3135void init_static_variables ( void )
@@ -35,6 +39,10 @@ void init_static_variables( void )
3539 f_invalid_table = &_invalid_table;
3640 f_altered_table = &_altered_table;
3741}
42+ #else
43+ extern NdbMutex *g_ndb_connection_mutex;
44+ static int ndb_dict_cache_count = 0 ;
45+ #endif // HAVE_CXXABI_H
3846
3947Ndb_local_table_info *
4048Ndb_local_table_info::create (NdbTableImpl *table_impl, Uint32 sz)
@@ -105,14 +113,41 @@ LocalDictCache::drop(const char * name){
105113GlobalDictCache::GlobalDictCache (){
106114 DBUG_ENTER (" GlobalDictCache::GlobalDictCache" );
107115 // Initialize static variables
116+ #if HAVE_CXXABI_H
108117 my_pthread_once (&once_control, init_static_variables);
118+ #else
119+ NdbMutex_Lock (g_ndb_connection_mutex);
120+ if (f_invalid_table == NULL )
121+ f_invalid_table = new NdbTableImpl ();
122+ if (f_altered_table == NULL )
123+ f_altered_table = new NdbTableImpl ();
124+ ndb_dict_cache_count++;
125+ NdbMutex_Unlock (g_ndb_connection_mutex);
126+ #endif HAVE_CXXABI_H
109127 m_tableHash.createHashTable ();
110128 m_waitForTableCondition = NdbCondition_Create ();
111129 DBUG_VOID_RETURN;
112130}
113131
114132GlobalDictCache::~GlobalDictCache (){
115133 DBUG_ENTER (" GlobalDictCache::~GlobalDictCache" );
134+ #if !HAVE_CXXABI_H
135+ NdbMutex_Lock (g_ndb_connection_mutex);
136+ if (--ndb_dict_cache_count == 0 )
137+ {
138+ if (f_invalid_table)
139+ {
140+ delete f_invalid_table;
141+ f_invalid_table = 0 ;
142+ }
143+ if (f_altered_table)
144+ {
145+ delete f_altered_table;
146+ f_altered_table = 0 ;
147+ }
148+ }
149+ NdbMutex_Unlock (g_ndb_connection_mutex);
150+ #endif // !HAVE_CXXABI_H
116151 NdbElement_t<Vector<TableVersion> > * curr = m_tableHash.getNext (0 );
117152 while (curr != 0 ){
118153 Vector<TableVersion> * vers = curr->theData ;
0 commit comments