UI: IocContainer: Extract create/deleteTlsIndex() functions.

This commit is contained in:
Nodir Temirkhodjaev 2021-06-03 09:54:41 +03:00
parent 78fe8b943f
commit e5ad07d207

View File

@ -9,8 +9,26 @@
namespace { namespace {
int g_tlsIndex = -1;
int g_nextTypeId = 0; int g_nextTypeId = 0;
int g_tlsIndex = -1;
void createTlsIndex()
{
if (g_tlsIndex == -1) {
g_tlsIndex = TlsAlloc();
if (g_tlsIndex == -1) {
qWarning() << "TlsAlloc error";
}
}
}
void deleteTlsIndex()
{
if (g_tlsIndex != -1) {
TlsFree(g_tlsIndex);
g_tlsIndex = -1;
}
}
} }
@ -20,10 +38,7 @@ IocContainer::~IocContainer()
{ {
autoDeleteAll(); autoDeleteAll();
if (g_tlsIndex != -1) { deleteTlsIndex();
TlsFree(g_tlsIndex);
g_tlsIndex = -1;
}
} }
void IocContainer::setObject(int typeId, IocObject *obj, quint8 flags) void IocContainer::setObject(int typeId, IocObject *obj, quint8 flags)
@ -108,12 +123,7 @@ void IocContainer::autoDelete(int typeId)
bool IocContainer::pinToThread() bool IocContainer::pinToThread()
{ {
if (g_tlsIndex == -1) { createTlsIndex();
g_tlsIndex = TlsAlloc();
if (g_tlsIndex == -1) {
qWarning() << "TlsAlloc error";
}
}
return TlsSetValue(g_tlsIndex, this); return TlsSetValue(g_tlsIndex, this);
} }