[*] C++20 coroutine support: recursive callstack

This commit is contained in:
Reece Wilson 2024-05-01 20:09:35 +01:00
parent c79a709f96
commit 195af26aa4
3 changed files with 31 additions and 3 deletions

View File

@ -111,11 +111,12 @@ namespace Aurora
struct AsyncConfig
{
bool bStartSchedularOnStartup { true }; // spawns the sched thread during the runtime initialization process, otherwise delegate it until the last min
bool bEnableLegacyTicks { false }; // turn this on to enable an async apps singleton threadpool to SysPump on worker id zero. Alternatively, use SetMainThreadForSysPumpScheduling once you have a thread pool and worker id.
bool bStartSchedularOnStartup { true }; // spawns the scheduler thread during the runtime initialization process, otherwise delegate the spawn until the very last minute.
bool bEnableLegacyTicks { false }; // turn this on to enable an async-app/singleton-threadpool to SysPump tick on thread worker-id: zero. Alternatively, use SetMainThreadForSysPumpScheduling once you have a thread pool and worker id.
AuUInt32 threadPoolDefaultStackSize { };
AuUInt32 dwSchedulerRateLimitNS { AuMSToNS<AuUInt64>(2) }; //
AuUInt32 dwLegacyMainThreadSystemTickMS { 60 }; // nowadays this is primarily used to dispatch main-thread posted (AuConsole) commands
AuUInt32 dwLegacyMainThreadSystemTickMS { 60 }; // nowadays this is used to dispatch AuConsole commands to a mainthread with AuAsync.
bool bEnableCpp20RecursiveCallstack { true }; // enables/disables co_routine support in that the runtime can work with nested IWorkItem::BlockUntilComplete()'s and IThreadPool::[Run/Poll/RunOnce/etc]()'s.
};
struct FIOConfig

View File

@ -293,7 +293,30 @@ namespace Aurora::Async
return bSuccess;
}
#if defined(__AUHAS_COROUTINES_CO_AWAIT) && defined(AU_LANG_CPP_20_)
AuVoidTask ThreadPool::PollInternal_ForceCoRoutine(AuSPtr<ThreadState> state, bool block, AuUInt32 &uCount, bool &bRet)
{
bRet = PollInternal_Base(state, block, uCount);
co_return;
}
#endif
bool ThreadPool::PollInternal(AuSPtr<ThreadState> state, bool block, AuUInt32 &uCount)
{
#if defined(__AUHAS_COROUTINES_CO_AWAIT) && defined(AU_LANG_CPP_20_)
if (state->stackState.uStackCallDepth &&
gRuntimeConfig.async.bEnableCpp20RecursiveCallstack)
{
bool bRet {};
PollInternal_ForceCoRoutine(state, block, uCount, bRet);
return bRet;
}
#endif
return PollInternal_Base(state, block, uCount);
}
bool ThreadPool::PollInternal_Base(AuSPtr<ThreadState> state, bool block, AuUInt32 &uCount)
{
if (!state)
{

View File

@ -101,6 +101,10 @@ namespace Aurora::Async
bool InternalRunOne(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount);
bool PollInternal(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount);
#if defined(__AUHAS_COROUTINES_CO_AWAIT) && defined(AU_LANG_CPP_20_)
AuVoidTask PollInternal_ForceCoRoutine(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount, bool &bRet);
#endif
bool PollInternal_Base(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount);
size_t GetThreadWorkersCount(ThreadGroup_t group);