[*] 2/4 critical bugs in legacy aurora engine async subsystem

This commit is contained in:
Reece Wilson 2022-05-10 14:22:37 +01:00
parent 1c7267b9d8
commit eeaa10090d
7 changed files with 36 additions and 21 deletions

View File

@ -44,8 +44,8 @@ namespace Aurora::Async
void AsyncApp::SetConsoleCommandDispatcher(WorkerId_t id)
{
commandDispatcher_ = id;
Console::Commands::UpdateDispatcher(commandDispatcher_);
this->commandDispatcher_ = id;
Console::Commands::UpdateDispatcher(WorkerPId_t(GetSharedAsyncApp(), id));
}
void AsyncApp::CleanUpWorker(WorkerId_t id)

View File

@ -10,6 +10,7 @@
#include "Schedular.hpp"
//#include "AsyncApp.hpp"
#include "ThreadPool.hpp"
#include <Console/Commands/Commands.hpp>
namespace Aurora::Async
{
@ -135,10 +136,13 @@ namespace Aurora::Async
{
gRuntimeConfig.async.enableSysPumpFreqnecy = gBOriginal;
gMainThread = AuWorkerPId_t(AuAsync::GetSharedAsyncApp(), AuWorkerId_t {0, 0});
Console::Commands::UpdateDispatcher(gMainThread);
return;
}
gMainThread = pid;
Console::Commands::UpdateDispatcher(gMainThread);
gRuntimeConfig.async.enableSysPumpFreqnecy = true;
StartSched2();
@ -152,7 +156,7 @@ namespace Aurora::Async
}
else
{
if (gRuntimeConfig.async.sysPumpFrequency)
if (gRuntimeConfig.async.sysPumpFrequency && !gMainThread)
{
gMainThread = AuWorkerPId_t(AuAsync::GetSharedAsyncApp(), AuWorkerId_t {0, 0});
}

View File

@ -23,7 +23,7 @@ namespace Aurora::Async
};
struct ThreadPool : public IThreadPool, public IThreadPoolInternal, AuEnableSharedFromThis<ThreadPool>
struct ThreadPool : IThreadPool, IThreadPoolInternal, AuEnableSharedFromThis<ThreadPool>
{
ThreadPool();

View File

@ -362,7 +362,7 @@ namespace Aurora::Async
return {};
}
return AuMakeShared<WorkItem>(GetWorkerInternal(), worker, task, supportsBlocking);
return AuMakeShared<WorkItem>(AuStaticCast<ThreadPool>(worker.pool).get(), worker, task, supportsBlocking);
}
AUKN_SYM AuSPtr<IWorkItem> NewFence()

View File

@ -145,7 +145,7 @@ namespace Aurora::Console::Commands
return Dispatch(string, EDispatchType::eAsync, id);
}
void UpdateDispatcher(AuOptional<Async::WorkerId_t> target)
void UpdateDispatcher(AuOptional<Async::WorkerPId_t> target)
{
AU_LOCK_GUARD(gMutex);
AU_LOCK_GUARD(gPendingCommandsMutex);
@ -160,7 +160,7 @@ namespace Aurora::Console::Commands
}
}
gCommandDispatcher = Async::WorkerPId_t(AuUnsafeRaiiToShared(AuAsync::GetAsyncApp()), target.value_or(AuAsync::ThreadGroup_t {}));
gCommandDispatcher = target.value();
}
static void DispatchCommandsFromThis(const AuList<CommandDispatch> &commands)
@ -171,6 +171,18 @@ namespace Aurora::Console::Commands
}
}
void RunCommandFunction(const AuFunction<void()> &func)
{
if (!gCommandDispatcher)
{
func();
}
else
{
NewWorkItem(gCommandDispatcher, AuMakeShared<Async::BasicWorkStdFunc>(func), true)->Dispatch()->BlockUntilComplete();
}
}
void PumpCommands()
{
AU_LOCK_GUARD(gMutex);
@ -179,21 +191,16 @@ namespace Aurora::Console::Commands
{
AU_LOCK_GUARD(gPendingCommandsMutex);
commands = AuExchange(gPendingCommands, {});
if (commands.empty())
{
return;
}
}
if ((gCommandDispatcher.pool == nullptr) ||
((gCommandDispatcher.pool.get() == Async::GetAsyncApp()) &&
(gCommandDispatcher == Async::WorkerId_t{})))
RunCommandFunction([&commands]()
{
DispatchCommandsFromThis(commands);
}
else
{
NewWorkItem(gCommandDispatcher,
AuMakeShared<Async::BasicWorkStdFunc>([&commands]()
{
DispatchCommandsFromThis(commands);
}), true)->Dispatch()->BlockUntilComplete();
}
});
}
}

View File

@ -9,6 +9,7 @@
namespace Aurora::Console::Commands
{
void UpdateDispatcher(AuOptional<Async::WorkerId_t> target);
void UpdateDispatcher(AuOptional<Async::WorkerPId_t> target);
void PumpCommands();
void RunCommandFunction(const AuFunction<void()> &func);
}

View File

@ -59,7 +59,10 @@ namespace Aurora::Console
{
if (Hooks::gExternalLineProcessor)
{
Hooks::gExternalLineProcessor->OnProcessedLineUTF8(string);
Commands::RunCommandFunction([&string]()
{
Hooks::gExternalLineProcessor->OnProcessedLineUTF8(string);
});
return true;
}