This example demonstrates usage of the coroutine scheduler run from the idle thread.
extern "C" {
void __cxa_pure_virtual(void) {}
void DebugPrint(const char* szString_);
}
namespace
{
void AppMain(void* unused_);
void IdleMain(void* unused_);
int iCounter1;
int iCounter2;
int iCounter3;
void CoroutineTask1(
Coroutine* pclCaller_,
void* pvArg_)
{
int* piCounter = static_cast<int*>(pvArg_);
(*piCounter)++;
}
void CoroutineTask2(
Coroutine* pclCaller_,
void* pvArg_)
{
int* piCounter = static_cast<int*>(pvArg_);
(*piCounter)++;
}
void CoroutineTask3(
Coroutine* pclCaller_,
void* pvArg_)
{
int* piCounter = static_cast<int*>(pvArg_);
(*piCounter)++;
}
void AppMain(void* unused_)
{
while (1) {
}
}
void IdleMain(void* unused_)
{
while (1) {
if (pclCoRoutine != nullptr) {
pclCoRoutine->Run();
}
}
}
}
int main(void)
{
clCoroutine1.Init(1, CoroutineTask1, &iCounter1);
clCoroutine2.Init(2, CoroutineTask2, &iCounter2);
clCoroutine3.Init(3, CoroutineTask3, &iCounter3);
clAppThread.Init(awAppStack, sizeof(awAppStack), 1, AppMain, 0);
clIdleThread.Init(awIdleStack, sizeof(awIdleStack), 0, IdleMain, 0);
clAppThread.Start();
clIdleThread.Start();
return 0;
}