[*] 4/6 fatal bugs in auAsync 1.0 grime

This commit is contained in:
Reece Wilson 2022-05-10 14:51:22 +01:00
parent eeaa10090d
commit b98baea2a8

View File

@ -21,6 +21,7 @@ namespace Aurora::Async
AUKN_SYM WorkerPId_t GetCurrentWorkerPId()
{
auto lkPool = gCurrentPool.lock();
if (!lkPool) return {};
auto cpy = *lkPool->tlsWorkerId;
auto lkPool2 = cpy.pool.lock();
return WorkerPId_t(lkPool, cpy);
@ -40,6 +41,11 @@ namespace Aurora::Async
{
auto curThread = GetThreadState();
if (!curThread)
{
return Threading::WaitFor(primitive.get(), timeoutMs);
}
bool workerIdMatches = (unlocker.second == curThread->id.second) || ((unlocker.second == Async::kThreadIdAny) && (GetThreadWorkersCount(unlocker.first) == 1));
if ((unlocker.first == curThread->id.first) && // work group matches
@ -207,6 +213,11 @@ namespace Aurora::Async
auto auThread = AuThreads::GetThread();
auto job = GetThreadState();
if (!job)
{
SysPushErrorUninitialized("Not an async thread");
}
while ((!auThread->Exiting()) && (!job->shuttingdown))
{
// Do work (blocking)
@ -220,6 +231,11 @@ namespace Aurora::Async
bool ThreadPool::InternalRunOne(bool block)
{
auto state = GetThreadState();
if (!state)
{
SysPushErrorUninitialized("Not an async thread");
}
bool success {};
auto runMode = GetCurrentThreadRunMode();
@ -303,6 +319,11 @@ namespace Aurora::Async
bool ThreadPool::PollInternal(bool block)
{
auto state = GetThreadState();
if (!state)
{
SysPushErrorUninitialized("Not an async thread");
}
auto group = state->parent.lock();
//state->pendingWorkItems.clear();
@ -439,7 +460,11 @@ namespace Aurora::Async
{
group->sorted = false;
if (lowPrioCont) continue;
if (lowPrioCont)
{
itr++;
continue;
}
if (!lowPrioContCached)
{
@ -456,7 +481,11 @@ namespace Aurora::Async
}
lowPrioContCached = true;
if (lowPrioCont) continue;
if (lowPrioCont)
{
itr++;
continue;
}
}
}
@ -1052,9 +1081,30 @@ namespace Aurora::Async
AuSPtr<ThreadState> ThreadPool::GetThreadState()
{
AU_LOCK_GUARD(this->rwlock_->AsReadable());
auto id = GetCurrentThread();
auto state = GetGroup(id.first);
return state->workers[id.second];
auto thread = gCurrentPool.lock();
if (!thread)
{
return {};
}
#if defined(AU_CFG_ID_INTERNAL) || defined(AU_CFG_ID_DEBUG)
if (thread.get() != this)
{
SysPushErrorGeneric("wrong thread");
return {};
}
#endif
auto worker = *tlsWorkerId;
auto state = GetGroup(worker.first);
if (!state)
{
return {};
}
return state->workers[worker.second];
}
AuSPtr<ThreadState> ThreadPool::GetThreadHandle(WorkerId_t id)