[*] Fix OSThread regression / main thread was stalling for a few seconds on exit because the schedulers end of thread clean up was bailing out under the "pls no dtor race before the os spawn kicks in" lock path

TODO: destink OSThread
This commit is contained in:
Reece Wilson 2023-10-01 14:12:22 +01:00
parent 16f7d985fc
commit cdad552ed0
2 changed files with 16 additions and 44 deletions

View File

@ -176,10 +176,7 @@ namespace Aurora::Threading::Threads
// Kill the current OS thread instance
TeminateOSContext(false);
if (this->exitOnlyOnce_)
{
this->exitOnlyOnce_->Unlock();
}
this->exitOnlyOnce_->Unlock();
#if defined(AURORA_IS_POSIX_DERIVED)
if (this->terminated_)
@ -370,10 +367,6 @@ namespace Aurora::Threading::Threads
return true;
}
if (!this->exitOnlyOnce_)
{
return true;
}
// attempt to join with the thread once it has exited, or timeout
if (this->terminated_->LockMS(this->qwExitTimeout))
@ -598,6 +591,7 @@ namespace Aurora::Threading::Threads
AU_LOCK_GUARD(pFlag->mutex);
if (pFlag->bLock)
{
this->SignalDeath();
return;
}
@ -626,25 +620,13 @@ namespace Aurora::Threading::Threads
// "Safer" update
this->HookOnExit();
if (this->terminated_)
{
if (this->exitOnlyOnce_)
{
this->exitOnlyOnce_->Unlock();
}
this->terminated_->Set();
}
if (this->terminatedSignalLs_)
{
this->terminatedSignalLs_->Set();
}
this->SignalDeath();
}
AU_LOCK_GUARD(pFlag->mutex);
if (pFlag->bLock)
{
this->SignalDeath();
return;
}
@ -1325,11 +1307,6 @@ namespace Aurora::Threading::Threads
{
if (!locked)
{
if (!this->exitOnlyOnce_)
{
return true;
}
if (!this->exitOnlyOnce_->TryLock())
{
return false;
@ -1359,6 +1336,13 @@ namespace Aurora::Threading::Threads
HookReleaseThreadResources();
this->SignalDeath();
return true;
}
void OSThread::SignalDeath()
{
if (this->terminatedSignalLs_)
{
this->terminatedSignalLs_->Set();
@ -1367,27 +1351,14 @@ namespace Aurora::Threading::Threads
if (this->terminated_)
{
this->exitOnlyOnce_->Unlock();
this->terminated_->Set(); // must be set last, after which point we cannot use this!
}
return true;
this->terminated_->Set();
}
}
bool OSThread::InternalKillForceNtfy()
{
if (this->terminated_)
{
if (this->exitOnlyOnce_)
{
this->exitOnlyOnce_->Unlock();
}
this->terminated_->Set();
}
if (this->terminatedSignalLs_)
{
this->terminatedSignalLs_->Set();
}
this->SignalDeath();
// Great C++ ABI guys...
#if defined(AURORA_HAS_PTHREADS)

View File

@ -53,6 +53,7 @@ namespace Aurora::Threading::Threads
AuSPtr<AuLoop::ILoopSource> GetShutdownSignalLS() override;
bool InternalKillForceNtfy();
void SignalDeath();
bool InternalKill(bool locked);
void AffinityPrioThrottleTickAmendECores();