diff --git a/Source/Threading/Threads/AuOSThread.cpp b/Source/Threading/Threads/AuOSThread.cpp index ac715944..1e07a854 100644 --- a/Source/Threading/Threads/AuOSThread.cpp +++ b/Source/Threading/Threads/AuOSThread.cpp @@ -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) diff --git a/Source/Threading/Threads/AuOSThread.hpp b/Source/Threading/Threads/AuOSThread.hpp index f7cb7bd5..eac4a9dd 100644 --- a/Source/Threading/Threads/AuOSThread.hpp +++ b/Source/Threading/Threads/AuOSThread.hpp @@ -53,6 +53,7 @@ namespace Aurora::Threading::Threads AuSPtr GetShutdownSignalLS() override; bool InternalKillForceNtfy(); + void SignalDeath(); bool InternalKill(bool locked); void AffinityPrioThrottleTickAmendECores();