[*] Fixup schedule failure rejection. Fixes crash during safe/good clean up.

This commit is contained in:
Reece Wilson 2022-08-13 22:59:44 +01:00
parent d03488eeb0
commit 30da4bce04
4 changed files with 19 additions and 9 deletions

View File

@ -193,11 +193,16 @@ namespace Aurora::Async
gThread.reset();
}
void Schedule(AuUInt64 ns, IThreadPoolInternal *pool, WorkerId_t target, AuSPtr<IAsyncRunnable> runnable)
bool Schedule(AuUInt64 ns, IThreadPoolInternal *pool, WorkerId_t target, AuSPtr<IAsyncRunnable> runnable)
{
// TODO (Reece): urgent
if (!gSchedLock)
{
return false;
}
AU_LOCK_GUARD(gSchedLock);
pool->IncrementTasksRunning();
gEntries.push_back({ns, target, runnable, pool});
return AuTryInsert(gEntries, SchedEntry {ns, target, runnable, pool});
}
void TerminateSceduledTasks(IThreadPoolInternal *pool, WorkerId_t target)

View File

@ -16,6 +16,6 @@ namespace Aurora::Async
void StartSched();
void StopSched();
void Schedule(AuUInt64 ns, IThreadPoolInternal *pool, WorkerId_t target, AuSPtr<IAsyncRunnable> runnable);
bool Schedule(AuUInt64 ns, IThreadPoolInternal *pool, WorkerId_t target, AuSPtr<IAsyncRunnable> runnable);
void TerminateSceduledTasks(IThreadPoolInternal *pool, WorkerId_t target);
}

View File

@ -192,14 +192,20 @@ namespace Aurora::Async
if (Time::CurrentClockNS() < this->dispatchTimeNs_)
{
Schedule();
if (!Schedule())
{
this->Fail();
}
return;
}
if (auto delay = AuExchange(delayTimeNs_, {}))
{
this->dispatchTimeNs_ = delay + Time::CurrentClockNS();
Schedule();
if (!Schedule())
{
this->Fail();
}
return;
}
@ -222,7 +228,6 @@ namespace Aurora::Async
Fail();
}
void WorkItem::RunAsync()
{
AU_LOCK_GUARD(this->lock);
@ -348,9 +353,9 @@ namespace Aurora::Async
return this->failed;
}
void WorkItem::Schedule()
bool WorkItem::Schedule()
{
Async::Schedule(this->dispatchTimeNs_, this->owner_, this->worker_, AuSharedFromThis());
return Async::Schedule(this->dispatchTimeNs_, this->owner_, this->worker_, AuSharedFromThis());
}
void WorkItem::SendOff()

View File

@ -69,7 +69,7 @@ namespace Aurora::Async
IThreadPoolInternal *owner_ {};
void Fail();
void Schedule();
bool Schedule();
void SendOff();
};
}