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() {
51 while (*current !=
nullptr) {
52 if ((*current)->isSuspended()) {
53 *current = *((*current)->getNext());
55 current = (*current)->getNext();
60 void CoroutineScheduler::runCoroutine() {
62 if (*mCurrent ==
nullptr) {
67 if (*mCurrent ==
nullptr) {
72 #if ACE_ROUTINE_DEBUG == 1
73 Serial.print(F(
"Processing "));
74 (*mCurrent)->printeName(Serial);
79 switch ((*mCurrent)->getStatus()) {
81 (*mCurrent)->runCoroutine();
82 mCurrent = (*mCurrent)->
getNext();
89 if ((*mCurrent)->isDelayExpired()) {
90 (*mCurrent)->runCoroutine();
92 mCurrent = (*mCurrent)->
getNext();
97 (*mCurrent)->setTerminated();
98 *mCurrent = *((*mCurrent)->getNext());
102 *mCurrent = *((*mCurrent)->getNext());
107 mCurrent = (*mCurrent)->
getNext();
112 void CoroutineScheduler::listCoroutines(Print& printer) {
115 printer.print(F(
"Coroutine "));
117 printer.print(F(
"; status: "));
118 (*p)->statusPrintTo(printer);