mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
Avoid thread-local storage in CLogCategoryList::fromClass
Use an ordinary function-local static variable instead. This ensures we can still log messages after thread-local storage is cleaned up.
This commit is contained in:
@@ -112,15 +112,16 @@ namespace BlackMisc
|
|||||||
static const CLogCategoryList &fromClass()
|
static const CLogCategoryList &fromClass()
|
||||||
{
|
{
|
||||||
static_assert(sizeof(T) > 0, "T must be a complete type, not forward declared");
|
static_assert(sizeof(T) > 0, "T must be a complete type, not forward declared");
|
||||||
static QThreadStorage<CLogCategoryList> list; //! \todo C++17: make list an inline static member variable template
|
static const auto list = []
|
||||||
if (! list.hasLocalData())
|
|
||||||
{
|
{
|
||||||
list.localData().appendCategoriesFromMemberFunction(tag<T>(), THasGetLogCategories<T>());
|
CLogCategoryList list;
|
||||||
list.localData().appendCategoriesFromMetaType(tag<T>(), std::integral_constant<bool, QMetaTypeId<T>::Defined>());
|
list.appendCategoriesFromMemberFunction(tag<T>(), THasGetLogCategories<T>());
|
||||||
list.localData().appendCategoriesFromMetaObject(tag<T>(), std::is_base_of<QObject, T>());
|
list.appendCategoriesFromMetaType(tag<T>(), std::integral_constant<bool, QMetaTypeId<T>::Defined>());
|
||||||
if (list.localData().isEmpty()) { list.localData().push_back(CLogCategory::uncategorized()); }
|
list.appendCategoriesFromMetaObject(tag<T>(), std::is_base_of<QObject, T>());
|
||||||
}
|
if (list.isEmpty()) { list.push_back(CLogCategory::uncategorized()); }
|
||||||
return list.localData();
|
return list;
|
||||||
|
}();
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user