27 #define ACE_ROUTINE_DEBUG 0 29 #include "CoroutineScheduler.h" 31 #if ACE_ROUTINE_DEBUG == 1 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);
static const Status kStatusEnding
Coroutine executed the COROUTINE_END() statement.
const FCString & getName() const
Human-readable name of the coroutine.
static const Status kStatusYielding
Coroutine returned using the COROUTINE_YIELD() statement.
static const Status kStatusSuspended
Coroutine has been suspended using suspend() and the scheduler should remove it from the queue upon t...
static const Status kStatusDelaying
Coroutine returned using the COROUTINE_DELAY() statement.
size_t printTo(Print &printer) const
Convenience method for printing an FCString to printer.
Coroutine ** getNext()
Return the next pointer as a pointer to the pointer, similar to getRoot().
static Coroutine ** getRoot()
Get the pointer to the root pointer.