@@ -149,12 +149,8 @@ class SB_Thread_Table_Entry_Mgr : public SB_Table_Entry_Mgr<SB_Thread_Ctx_Type>
149149static void sb_thread_ctx_key_dtor (void *pp_ctx);
150150static void sb_thread_name_key_dtor (void *pp_name);
151151
152- SB_Thread_Table_Entry_Mgr gv_sb_thread_table_entry_mgr;
153- SB_Ts_Table_Mgr<SB_Thread_Ctx_Type> gv_sb_thread_table (" tablemgr-THREAD-MGR" ,
154- SB_Table_Mgr_Alloc::ALLOC_FAST,
155- SB_Table_Mgr_Alloc::ALLOC_ENTRY_DYN,
156- &gv_sb_thread_table_entry_mgr,
157- 10 , 10 ); // cap-init, cap-inc
152+ SB_Ts_Table_Mgr<SB_Thread_Ctx_Type> *gv_sb_thread_table = NULL ;
153+ SB_Thread_Table_Entry_Mgr *gv_sb_thread_table_entry_mgr = NULL ;
158154static int gv_sb_thread_ctx_tls_inx =
159155 SB_create_tls_key (sb_thread_ctx_key_dtor,
160156 " thread-ctx" );
@@ -166,6 +162,24 @@ static int gv_sb_thread_name_tls_inx =
166162SB_Thread_Lock_Stats gv_sb_lock_stats;
167163#endif
168164
165+ SB_Ts_Table_Mgr<SB_Thread_Ctx_Type> *getGlobalTsTableMgr () {
166+ if (gv_sb_thread_table != NULL )
167+ return gv_sb_thread_table;
168+ SB_util_short_lock ();
169+ if (gv_sb_thread_table != NULL ) {
170+ SB_util_short_unlock ();
171+ return gv_sb_thread_table;
172+ }
173+ gv_sb_thread_table_entry_mgr = new SB_Thread_Table_Entry_Mgr ();
174+ gv_sb_thread_table = new SB_Ts_Table_Mgr<SB_Thread_Ctx_Type> (" tablemgr-THREAD-MGR" ,
175+ SB_Table_Mgr_Alloc::ALLOC_FAST,
176+ SB_Table_Mgr_Alloc::ALLOC_ENTRY_DYN,
177+ gv_sb_thread_table_entry_mgr,
178+ 10 , 10 ); // cap-init, cap-inc
179+ SB_util_short_unlock ();
180+ return gv_sb_thread_table;
181+ }
182+
169183
170184typedef struct Sthr_Disp {
171185 int iv_ctx_id;
@@ -189,7 +203,7 @@ static void sb_thread_ctx_key_dtor(void *pp_ctx) {
189203 trace_where_printf (WHERE,
190204 " thread exiting ctx-id=%d, name=%s\n " ,
191205 lp_ctx->iv_ctx_id , lp_ctx->ia_thread_name );
192- gv_sb_thread_table. free_entry (lp_ctx->iv_ctx_id );
206+ getGlobalTsTableMgr ()-> free_entry (lp_ctx->iv_ctx_id );
193207}
194208
195209static void sb_thread_name_key_dtor (void *pp_name) {
@@ -232,7 +246,7 @@ static void *sb_thread_sthr_disp(void *pp_arg) {
232246 lp_arg = lp_disp->ip_arg ;
233247 lp_name = lp_disp->ip_name ;
234248 lv_ctx_id = lp_disp->iv_ctx_id ;
235- lp_ctx = gv_sb_thread_table. get_entry (lv_ctx_id);
249+ lp_ctx = getGlobalTsTableMgr ()-> get_entry (lv_ctx_id);
236250 lp_ctx->ip_fun = lp_fun;
237251 lp_ctx->iv_self = pthread_self ();
238252 lp_ctx->iv_tid = gettid ();
@@ -261,8 +275,8 @@ void SB_thread_main() {
261275 SB_Thread_Ctx_Type *lp_ctx;
262276 int lv_ctx_id;
263277
264- lv_ctx_id = static_cast <int >(gv_sb_thread_table. alloc_entry ());
265- lp_ctx = gv_sb_thread_table. get_entry (lv_ctx_id);
278+ lv_ctx_id = static_cast <int >(getGlobalTsTableMgr ()-> alloc_entry ());
279+ lp_ctx = getGlobalTsTableMgr ()-> get_entry (lv_ctx_id);
266280 lp_ctx->iv_ctx_id = lv_ctx_id;
267281 strcpy (lp_ctx->ia_thread_name , " main" );
268282 lp_ctx->iv_self = pthread_self ();
@@ -282,9 +296,9 @@ SB_Thread::Sthr::Id_Ptr SB_Thread::Sthr::create(char *pp_name,
282296 lp_disp->ip_arg = pp_arg;
283297 lp_disp->ip_name = pp_name;
284298
285- lp_disp->iv_ctx_id = static_cast <int >(gv_sb_thread_table. alloc_entry ());
299+ lp_disp->iv_ctx_id = static_cast <int >(getGlobalTsTableMgr ()-> alloc_entry ());
286300 SB_Thread_Ctx_Type *lp_ctx =
287- gv_sb_thread_table. get_entry (lp_disp->iv_ctx_id );
301+ getGlobalTsTableMgr ()-> get_entry (lp_disp->iv_ctx_id );
288302 lp_ctx->iv_ctx_id = lp_disp->iv_ctx_id ;
289303 lp_ctx->ia_thread_name [sizeof (lp_ctx->ia_thread_name )-1 ] = ' \0 ' ;
290304 strncpy (lp_ctx->ia_thread_name ,
0 commit comments