[*] Always attach to the main thread context on init
This commit is contained in:
parent
31319981ba
commit
49ced3fcc6
@ -94,6 +94,7 @@ namespace Aurora::Threading::Threads
|
||||
this->terminateSignal_ = AuThreadPrimitives::EventShared(true, false, true);
|
||||
|
||||
SysAssert(this->terminated_ && this->terminateSignal_);
|
||||
this->bNotOwned = true;
|
||||
}
|
||||
|
||||
OSThread::OSThread(AuUInt64 id) : info_(gDummyThreadInfo)
|
||||
@ -174,8 +175,19 @@ namespace Aurora::Threading::Threads
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (auto pTerminated = AuExchange(this->terminatedSignalLs_, {}))
|
||||
{
|
||||
pTerminated->Set();
|
||||
}
|
||||
|
||||
if (auto pTerminated = AuExchange(this->terminated_, {}))
|
||||
{
|
||||
pTerminated->Set();
|
||||
}
|
||||
}
|
||||
|
||||
this->terminated_.reset();
|
||||
FreeOSContext();
|
||||
|
||||
if (bDetached)
|
||||
@ -728,10 +740,15 @@ namespace Aurora::Threading::Threads
|
||||
#endif
|
||||
}
|
||||
|
||||
void OSThread::MakeMain()
|
||||
{
|
||||
this->bNotOwned = true;
|
||||
this->name_ = "Main System Thread";
|
||||
this->OSAttach();
|
||||
}
|
||||
|
||||
void OSThread::OSAttach()
|
||||
{
|
||||
this->bSupportsAltKill = true;
|
||||
|
||||
HandleRegister(this);
|
||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||
this->unixThreadId_ = gettid();
|
||||
@ -759,11 +776,17 @@ namespace Aurora::Threading::Threads
|
||||
{
|
||||
SetThreadKey(this->tls_);
|
||||
}
|
||||
|
||||
UpdatePrio(this->throttle_, this->prio_);
|
||||
SetAffinity(this->mask_);
|
||||
AffinityPrioThrottleTickAmendECores();
|
||||
UpdateName();
|
||||
AttachSignalKiller();
|
||||
|
||||
if (!this->bNotOwned)
|
||||
{
|
||||
this->bSupportsAltKill = true;
|
||||
AttachSignalKiller();
|
||||
}
|
||||
}
|
||||
|
||||
static AuHashMap<EThreadPriority, int> kNiceMap
|
||||
@ -1417,5 +1440,10 @@ namespace Aurora::Threading::Threads
|
||||
#endif
|
||||
|
||||
AttachSignalKiller();
|
||||
|
||||
if (auto pThread = GetThread())
|
||||
{
|
||||
AuStaticCast<OSThread>(pThread)->MakeMain();
|
||||
}
|
||||
}
|
||||
}
|
@ -56,6 +56,9 @@ namespace Aurora::Threading::Threads
|
||||
bool InternalKill(bool locked);
|
||||
|
||||
void AffinityPrioThrottleTickAmendECores();
|
||||
|
||||
// !protected!
|
||||
void MakeMain();
|
||||
protected:
|
||||
|
||||
bool Exit(bool willReturnToOS, bool isEOL = false);
|
||||
@ -84,7 +87,6 @@ namespace Aurora::Threading::Threads
|
||||
HWInfo::CpuBitId throttleMask_ = HWInfo::CpuBitId().Not();
|
||||
EThreadPriority prio_ = EThreadPriority::ePrioNormal;
|
||||
EThreadThrottle throttle_ = EThreadThrottle::eNormal;
|
||||
bool bNotOwned {};
|
||||
bool bSupportsAltKill {};
|
||||
bool userManagingAffinity_ {};
|
||||
bool exiting_{};
|
||||
@ -95,8 +97,8 @@ namespace Aurora::Threading::Threads
|
||||
AuSPtr<AuLoop::ILSEvent> terminatedSignalLs_;
|
||||
bool bLongJmpOnce {};
|
||||
AuUInt64 qwExitTimeout { AuSToMS<AuUInt64>(15) };
|
||||
bool bNotOwned {};
|
||||
Primitives::CriticalSection exitOnlyOnce_;
|
||||
|
||||
AuList<AuSPtr<IThreadFeature>> threadFeatures_;
|
||||
|
||||
AuFunction<void()> task_;
|
||||
|
Loading…
Reference in New Issue
Block a user