From bad1b2fafac6cb3e703289aab4f566be0f6b6956 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sat, 5 Jun 2021 18:01:28 +0300 Subject: [PATCH] UI: IocContainer: Inline the TlsGetValue(). --- src/ui/util/ioc/ioccontainer.cpp | 48 +++++++++++--------------------- src/ui/util/ioc/ioccontainer.h | 14 +++++++++- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/ui/util/ioc/ioccontainer.cpp b/src/ui/util/ioc/ioccontainer.cpp index 64aae43c..75b6cbb2 100644 --- a/src/ui/util/ioc/ioccontainer.cpp +++ b/src/ui/util/ioc/ioccontainer.cpp @@ -2,37 +2,9 @@ #include -#define WIN32_LEAN_AND_MEAN -#include - #include "iocservice.h" -namespace { - -int g_nextTypeId = 0; -int g_tlsIndex = -1; - -void createTlsIndex() -{ - if (g_tlsIndex == -1) { - g_tlsIndex = TlsAlloc(); - if (g_tlsIndex == -1) { - qWarning() << "TlsAlloc error"; - } - } -} - -#if 0 -void deleteTlsIndex() -{ - if (g_tlsIndex != -1) { - TlsFree(g_tlsIndex); - g_tlsIndex = -1; - } -} -#endif - -} +int IocContainer::g_tlsIndex = -1; IocContainer::IocContainer(QObject *parent) : QObject(parent) { } @@ -118,12 +90,26 @@ bool IocContainer::pinToThread() return TlsSetValue(g_tlsIndex, this); } -IocContainer *IocContainer::getPinned() +void IocContainer::createTlsIndex() { - return static_cast(TlsGetValue(g_tlsIndex)); + if (g_tlsIndex == -1) { + g_tlsIndex = TlsAlloc(); + if (g_tlsIndex == -1) { + qWarning() << "TlsAlloc error"; + } + } +} + +void IocContainer::deleteTlsIndex() +{ + if (g_tlsIndex != -1) { + TlsFree(g_tlsIndex); + g_tlsIndex = -1; + } } int IocContainer::getNextTypeId() { + static int g_nextTypeId = 0; return g_nextTypeId++; } diff --git a/src/ui/util/ioc/ioccontainer.h b/src/ui/util/ioc/ioccontainer.h index 63b274a3..fdfdb2f4 100644 --- a/src/ui/util/ioc/ioccontainer.h +++ b/src/ui/util/ioc/ioccontainer.h @@ -4,6 +4,9 @@ #include #include +#define WIN32_LEAN_AND_MEAN +#include + #include "iocservice.h" using IocObject = void; @@ -79,7 +82,10 @@ public: bool pinToThread(); - static IocContainer *getPinned(); + inline static IocContainer *getPinned() + { + return static_cast(TlsGetValue(g_tlsIndex)); + } template static int getTypeId() @@ -101,10 +107,16 @@ private: void tearDown(int typeId); void autoDelete(int typeId); + static void createTlsIndex(); + static void deleteTlsIndex(); + static int getNextTypeId(); private: + static int g_tlsIndex; + int m_size = 0; + QVarLengthArray m_objects; QVarLengthArray m_objectFlags; };