| 108 | } |
| 109 | |
| 110 | void CoroutineContext::resume() FL_NOEXCEPT { |
| 111 | if (mCompleted) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | auto& platform = ICoroutinePlatform::instance(); |
| 116 | |
| 117 | // ISR guard — context switching from interrupt handler corrupts state |
| 118 | if (platform.inInterruptContext()) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | // Re-entrancy guard: if another coroutine is already running (e.g. a |
| 123 | // coroutine called suspend() which re-entered run()), skip. There's |
| 124 | // only one runner context save slot — a nested contextSwitch would |
| 125 | // overwrite it. |
| 126 | if (globals().current != nullptr) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | globals().current = this; |
| 131 | mStarted = true; |
| 132 | |
| 133 | void* runner = get_runner_ctx(); |
| 134 | platform.contextSwitch(runner, mPlatformCtx); |
| 135 | |
| 136 | // We're back — coroutine suspended or completed |
| 137 | globals().current = nullptr; |
| 138 | } |
| 139 | |
| 140 | CoroutineContext* CoroutineContext::runningCoroutine() FL_NOEXCEPT { |
| 141 | return globals().current; |
no test coverage detected