[*] Bug fixes

This commit is contained in:
Reece Wilson 2023-10-25 20:08:42 +01:00
parent ec8f3b3f23
commit deaa18ab07
4 changed files with 42 additions and 28 deletions

View File

@ -39,6 +39,31 @@ namespace Aurora::Async
return itr->second;
}
void GroupState::Decommit(ThreadId_t id)
{
if (AuArraySize(this->wpWorkers) > id)
{
this->wpWorkers[id] = {};
}
AU_LOCK_GUARD(this->workersMutex);
for (auto itr = this->workers.begin();
itr != this->workers.end();
)
{
auto &[id2, pWorker] = *itr;
if (id == id2)
{
itr = this->workers.erase(itr);
}
else
{
itr++;
}
}
}
void GroupState::BroadCast()
{
AU_LOCK_GUARD(this->workersMutex);

View File

@ -38,6 +38,7 @@ namespace Aurora::Async
bool Init();
void BroadCast();
void Decommit(ThreadId_t id);
void AddWorker(ThreadId_t id, AuSPtr<ThreadState> pState);

View File

@ -790,9 +790,8 @@ namespace Aurora::Async
if (handle)
{
handle->rejecting = false;
handle->isDeadEvent->LockMS(250);
}
handle->isDeadEvent->LockMS(250);
}
}
@ -1510,47 +1509,39 @@ namespace Aurora::Async
auto id = GetCurrentThread();
auto state = GetGroup(id.first);
auto pLocalState = state->GetThreadByIndex(id.second);
AuList<AuSPtr<AuThreads::IThreadFeature>> features;
{
//AU_LOCK_GUARD(this->rwlock_->AsWritable());
AU_LOCK_GUARD(this->rwlock_->AsReadable());
auto itr = state->workers.find(id.second);
auto &jobWorker = itr->second;
jobWorker->isDeadEvent->Set();
pLocalState->isDeadEvent->Set();
CleanUpWorker(id);
// Abort scheduled tasks
TerminateSceduledTasks(this, id);
// Prevent deadlocks
jobWorker->syncSema->Unlock(10); // prevent ::Barrier dead-locks
pLocalState->syncSema->Unlock(10); // prevent ::Barrier dead-locks
{
AU_LOCK_GUARD(jobWorker->externalFencesLock);
jobWorker->exitingflag2 = true;
AU_LOCK_GUARD(pLocalState->externalFencesLock);
pLocalState->exitingflag2 = true;
for (const auto &pIWaitable : jobWorker->externalFences)
for (const auto &pIWaitable : pLocalState->externalFences)
{
pIWaitable->Unlock();
}
jobWorker->externalFences.clear();
pLocalState->externalFences.clear();
}
{
AU_LOCK_GUARD(jobWorker->featuresMutex);
features = AuExchange(jobWorker->features, {});
AU_LOCK_GUARD(pLocalState->featuresMutex);
features = AuExchange(pLocalState->features, {});
}
}
{
// Clean up thread features
// -> transferable TLS handles
// -> thread specific vms
// -> anything your brain wishes to imagination
for (const auto &thread : features)
{
try
@ -1559,8 +1550,7 @@ namespace Aurora::Async
}
catch (...)
{
AuLogWarn("Couldn't clean up thread feature!");
Debug::PrintError();
SysPushErrorConcurrentRejected("Couldn't clean up thread feature!");
}
}
@ -1569,9 +1559,7 @@ namespace Aurora::Async
{
AU_LOCK_GUARD(this->rwlock_->AsWritable());
auto itr = state->workers.find(id.second);
auto &jobWorker = itr->second;
state->workers.erase(itr);
state->Decommit(id.second);
}
}

View File

@ -106,9 +106,9 @@ namespace Aurora::Logging
while (!AuTryInsert(gLogTasks, AuMakeTuple(this, uLevel, AuConstReference(msg))))
{
SysPushErrorMem("Push failed - trying again");
spin.Unlock();
gTaskSpin->Unlock();
AuThreading::ContextYield();
spin.Lock();
gTaskSpin->Lock();
}
}