@@ -242,17 +242,23 @@ int LogPrint(const char* category, const char* pszFormat, ...)
242
242
if (!fDebug )
243
243
return 0 ;
244
244
245
- const vector<string>& categories = mapMultiArgs[ " -debug" ];
246
- bool allCategories = count (categories. begin (), categories. end (), string ( " " ));
247
-
248
- // Only look for categories, if not -debug/-debug=1 was passed,
249
- // as that implies every category should be logged.
250
- if (!allCategories )
245
+ // Give each thread quick access to -debug settings.
246
+ // This helps prevent issues debugging global destructors,
247
+ // where mapMultiArgs might be deleted before another
248
+ // global destructor calls LogPrint()
249
+ static boost::thread_specific_ptr<set<string> > ptrCategory;
250
+ if (ptrCategory. get () == NULL )
251
251
{
252
- // Category was not found (not supplied via -debug=<category>)
253
- if ( find ( categories.begin (), categories.end (), string (category)) == categories. end ())
254
- return 0 ;
252
+ const vector<string>& categories = mapMultiArgs[ " -debug" ];
253
+ ptrCategory. reset ( new set<string>( categories.begin (), categories.end ()));
254
+ // thread_specific_ptr automatically deletes the set when the thread ends.
255
255
}
256
+ const set<string>& setCategories = *ptrCategory.get ();
257
+
258
+ // if not debugging everything and not debugging specific category, LogPrint does nothing.
259
+ if (setCategories.count (string (" " )) == 0 &&
260
+ setCategories.count (string (category)) == 0 )
261
+ return 0 ;
256
262
}
257
263
258
264
int ret = 0 ; // Returns total number of characters written
0 commit comments