[*] 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; 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() void GroupState::BroadCast()
{ {
AU_LOCK_GUARD(this->workersMutex); AU_LOCK_GUARD(this->workersMutex);

View File

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

View File

@ -790,11 +790,10 @@ namespace Aurora::Async
if (handle) if (handle)
{ {
handle->rejecting = false; handle->rejecting = false;
}
handle->isDeadEvent->LockMS(250); handle->isDeadEvent->LockMS(250);
} }
} }
}
// Sync to shutdown threads to prevent a race condition whereby the async subsystem shuts down before the threads // Sync to shutdown threads to prevent a race condition whereby the async subsystem shuts down before the threads
for (const auto &thread : threads) for (const auto &thread : threads)
@ -1510,47 +1509,39 @@ namespace Aurora::Async
auto id = GetCurrentThread(); auto id = GetCurrentThread();
auto state = GetGroup(id.first); auto state = GetGroup(id.first);
auto pLocalState = state->GetThreadByIndex(id.second);
AuList<AuSPtr<AuThreads::IThreadFeature>> features; AuList<AuSPtr<AuThreads::IThreadFeature>> features;
{ {
//AU_LOCK_GUARD(this->rwlock_->AsWritable());
AU_LOCK_GUARD(this->rwlock_->AsReadable()); AU_LOCK_GUARD(this->rwlock_->AsReadable());
auto itr = state->workers.find(id.second); pLocalState->isDeadEvent->Set();
auto &jobWorker = itr->second;
jobWorker->isDeadEvent->Set();
CleanUpWorker(id); CleanUpWorker(id);
// Abort scheduled tasks
TerminateSceduledTasks(this, id); TerminateSceduledTasks(this, id);
// Prevent deadlocks pLocalState->syncSema->Unlock(10); // prevent ::Barrier dead-locks
jobWorker->syncSema->Unlock(10); // prevent ::Barrier dead-locks
{ {
AU_LOCK_GUARD(jobWorker->externalFencesLock); AU_LOCK_GUARD(pLocalState->externalFencesLock);
jobWorker->exitingflag2 = true; pLocalState->exitingflag2 = true;
for (const auto &pIWaitable : jobWorker->externalFences) for (const auto &pIWaitable : pLocalState->externalFences)
{ {
pIWaitable->Unlock(); pIWaitable->Unlock();
} }
jobWorker->externalFences.clear(); pLocalState->externalFences.clear();
} }
{ {
AU_LOCK_GUARD(jobWorker->featuresMutex); AU_LOCK_GUARD(pLocalState->featuresMutex);
features = AuExchange(jobWorker->features, {}); 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) for (const auto &thread : features)
{ {
try try
@ -1559,8 +1550,7 @@ namespace Aurora::Async
} }
catch (...) catch (...)
{ {
AuLogWarn("Couldn't clean up thread feature!"); SysPushErrorConcurrentRejected("Couldn't clean up thread feature!");
Debug::PrintError();
} }
} }
@ -1569,9 +1559,7 @@ namespace Aurora::Async
{ {
AU_LOCK_GUARD(this->rwlock_->AsWritable()); AU_LOCK_GUARD(this->rwlock_->AsWritable());
auto itr = state->workers.find(id.second); state->Decommit(id.second);
auto &jobWorker = itr->second;
state->workers.erase(itr);
} }
} }

View File

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