UI: IocContainer: Inline the TlsGetValue().

This commit is contained in:
Nodir Temirkhodjaev 2021-06-05 18:01:28 +03:00
parent 19845e5b9f
commit bad1b2fafa
2 changed files with 30 additions and 32 deletions

View File

@ -2,37 +2,9 @@
#include <QDebug> #include <QDebug>
#define WIN32_LEAN_AND_MEAN
#include <qt_windows.h>
#include "iocservice.h" #include "iocservice.h"
namespace { int IocContainer::g_tlsIndex = -1;
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
}
IocContainer::IocContainer(QObject *parent) : QObject(parent) { } IocContainer::IocContainer(QObject *parent) : QObject(parent) { }
@ -118,12 +90,26 @@ bool IocContainer::pinToThread()
return TlsSetValue(g_tlsIndex, this); return TlsSetValue(g_tlsIndex, this);
} }
IocContainer *IocContainer::getPinned() void IocContainer::createTlsIndex()
{ {
return static_cast<IocContainer *>(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() int IocContainer::getNextTypeId()
{ {
static int g_nextTypeId = 0;
return g_nextTypeId++; return g_nextTypeId++;
} }

View File

@ -4,6 +4,9 @@
#include <QObject> #include <QObject>
#include <QVarLengthArray> #include <QVarLengthArray>
#define WIN32_LEAN_AND_MEAN
#include <qt_windows.h>
#include "iocservice.h" #include "iocservice.h"
using IocObject = void; using IocObject = void;
@ -79,7 +82,10 @@ public:
bool pinToThread(); bool pinToThread();
static IocContainer *getPinned(); inline static IocContainer *getPinned()
{
return static_cast<IocContainer *>(TlsGetValue(g_tlsIndex));
}
template<class T> template<class T>
static int getTypeId() static int getTypeId()
@ -101,10 +107,16 @@ private:
void tearDown(int typeId); void tearDown(int typeId);
void autoDelete(int typeId); void autoDelete(int typeId);
static void createTlsIndex();
static void deleteTlsIndex();
static int getNextTypeId(); static int getNextTypeId();
private: private:
static int g_tlsIndex;
int m_size = 0; int m_size = 0;
QVarLengthArray<IocObject *, IOC_DEFAULT_SIZE> m_objects; QVarLengthArray<IocObject *, IOC_DEFAULT_SIZE> m_objects;
QVarLengthArray<quint8, IOC_DEFAULT_SIZE> m_objectFlags; QVarLengthArray<quint8, IOC_DEFAULT_SIZE> m_objectFlags;
}; };