[+] IAuroraThread::SetNoUnwindTerminateExitWatchDogTimeoutInMS

This commit is contained in:
Reece Wilson 2023-08-23 17:01:56 +01:00
parent 412630077d
commit 921fee1b8d
3 changed files with 18 additions and 10 deletions

View File

@ -57,6 +57,8 @@ namespace Aurora::Threading::Threads
/// Use this to register teardown functions
virtual void AddLastHopeTlsHook(const AuSPtr<Threading::Threads::IThreadFeature> &feature) = 0;
virtual AuUInt64 SetNoUnwindTerminateExitWatchDogTimeoutInMS(AuUInt64 uMS) = 0;
virtual AuSPtr<TLSView> GetTlsView() = 0;
virtual AuSPtr<IWaitable> AsWaitable() = 0;
@ -65,11 +67,6 @@ namespace Aurora::Threading::Threads
virtual AuSPtr<IWaitable> GetShutdownSignalWaitable() = 0;
virtual AuSPtr<IO::Loop::ILoopSource> GetShutdownSignalLS() = 0;
// TODO: consider detach support.
// The problem is, if the aurora runtime transfers ownership of an IAuroraThread to you, you have to leak it
// or you have to be forced to use the very comfy dtor mechanic. We need a detach function to overload this
// release-is-always-terminate assumption.
// UPDATE: DONE
virtual void Detach() = 0;
virtual void ExecuteInDeadThread(AuFunction<void()> callback) = 0;

View File

@ -218,6 +218,16 @@ namespace Aurora::Threading::Threads
}
}
AuUInt64 OSThread::SetNoUnwindTerminateExitWatchDogTimeoutInMS(AuUInt64 uMS)
{
if (!uMS)
{
uMS = AuSToMS<AuUInt64>(15);
}
qwExitTimeout = uMS;
}
void OSThread::AddLastHopeTlsHook(const AuSPtr<AuThreads::IThreadFeature> &feature)
{
AU_LOCK_GUARD(this->tlsLock_);
@ -334,7 +344,7 @@ namespace Aurora::Threading::Threads
}
// attempt to join with the thread once it has exited, or timeout
if (WaitFor(this->terminated_.get(), 15 * 1000))
if (this->terminated_->LockMS(this->qwExitTimeout))
{
return true;
}
@ -343,11 +353,11 @@ namespace Aurora::Threading::Threads
// The thread must've requested suicide and got stuck in a lengthy clean up effort
if (!this->exitOnlyOnce_->TryLock())
{
AuLogWarn("Watchdog error - OS thread context didn't finish in 15 seconds, but he should exiting now.");
AuLogWarn("Watchdog error - OS thread context didn't finish in {} MS, but he should exiting now.", this->qwExitTimeout);
return false;
}
AuLogWarn("Watchdog error - OS thread context didn't finish in 15 seconds, forcefully terminating without a watchdog overlooking onExit");
AuLogWarn("Watchdog error - OS thread context didn't finish in {} MS, forcefully terminating without a watchdog overlooking onExit", this->qwExitTimeout);
// Kill the current OS thread instance
TeminateOSContext(false);

View File

@ -43,6 +43,7 @@ namespace Aurora::Threading::Threads
AuSPtr<IWaitable> AsWaitable() override;
void AddLastHopeTlsHook(const AuSPtr<Threading::Threads::IThreadFeature> &feature) override;
AuUInt64 SetNoUnwindTerminateExitWatchDogTimeoutInMS(AuUInt64 uMS) override;
void Detach() override;
@ -93,7 +94,7 @@ namespace Aurora::Threading::Threads
AuSPtr<AuLoop::ILSEvent> terminateSignalLs_;
AuSPtr<AuLoop::ILSEvent> terminatedSignalLs_;
bool bLongJmpOnce {};
AuUInt64 qwExitTimeout { AuSToMS<AuUInt64>(15) };
Primitives::CriticalSection exitOnlyOnce_;
AuList<AuSPtr<IThreadFeature>> threadFeatures_;