27 #define ACE_ROUTINE_DEBUG 0
29 #include "CoroutineScheduler.h"
31 #if ACE_ROUTINE_DEBUG == 1
35 namespace ace_routine {
37 CoroutineScheduler* CoroutineScheduler::getScheduler() {
38 static CoroutineScheduler singletonScheduler;
39 return &singletonScheduler;
42 void CoroutineScheduler::setupScheduler() {
43 mCurrent = Coroutine::getRoot();
69 void CoroutineScheduler::runCoroutine() {
71 if (*mCurrent ==
nullptr) {
72 mCurrent = Coroutine::getRoot();
76 if (*mCurrent ==
nullptr) {
81 #if ACE_ROUTINE_DEBUG == 1
82 Serial.print(F(
"Processing "));
83 (*mCurrent)->getName().printTo(Serial);
88 switch ((*mCurrent)->getStatus()) {
90 (*mCurrent)->runCoroutine();
98 if ((*mCurrent)->isDelayExpired()) {
99 (*mCurrent)->runCoroutine();
105 (*mCurrent)->setTerminated();
114 mCurrent = (*mCurrent)->getNext();
117 void CoroutineScheduler::listCoroutines(Print& printer) {
118 for (Coroutine** p = Coroutine::getRoot(); (*p) !=
nullptr;
119 p = (*p)->getNext()) {
120 printer.print(F(
"Coroutine "));
121 (*p)->
getName().printTo(printer);
122 printer.print(F(
"; status: "));
123 (*p)->statusPrintTo(printer);