diff --git a/emper/Dispatcher.cpp b/emper/Dispatcher.cpp index 2499cad08cfd38009c2ebdd69385e103f485bac9..af53cebe09fa6943c1a842b73a0680a081ca8b46 100644 --- a/emper/Dispatcher.cpp +++ b/emper/Dispatcher.cpp @@ -15,8 +15,25 @@ void Dispatcher::dispatchLoopDoSleep() { runtime.maybeTerminateWorker(); if constexpr (emper::WORKER_SLEEP) { - runtime.dispatchLoopSleep(); + dispatchLoopSleep(); } else { sched_yield(); } } + +void Dispatcher::dispatchLoopSleep() { + auto& wakeupStrategy = runtime.wakeupStrategy; + auto& workerSleepStrategy = runtime.workerSleepStrategy; + auto& terminateWorkers = runtime.terminateWorkers; + + bool canWake; + do { + // Notify the wakeup strategy about our sleep attempt + if (!wakeupStrategy.canSleep()) break; + + workerSleepStrategy.sleep(); + + // We always wakeup if the runtime is terminating + canWake = wakeupStrategy.canWakeup() || terminateWorkers.load(std::memory_order_relaxed); + } while (!canWake); +} diff --git a/emper/Dispatcher.hpp b/emper/Dispatcher.hpp index 60e299aa6e8287add6d4d7ea12e34201619f5eba..363c7732c62be89637d5bba368b508da199c325c 100644 --- a/emper/Dispatcher.hpp +++ b/emper/Dispatcher.hpp @@ -13,6 +13,9 @@ class Runtime; class ContextManager; class Dispatcher : public Logger<LogSubsystem::DISP> { + private: + void dispatchLoopSleep(); + protected: Runtime& runtime; diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp index 40681e9da0abc6eca5f19c6688b4dfc30ab372f0..4fefbd5101d2c5dc2b6ebfe368650a10e68f188c 100644 --- a/emper/Runtime.hpp +++ b/emper/Runtime.hpp @@ -166,19 +166,6 @@ class Runtime : public Logger<LogSubsystem::RUNTI> { void maybeTerminateWorker(); - void dispatchLoopSleep() { - bool canWake; - do { - // Notify the wakeup strategy about our sleep attempt - if (!wakeupStrategy.canSleep()) break; - - workerSleepStrategy.sleep(); - - // We always wakeup if the runtime is terminating - canWake = wakeupStrategy.canWakeup() || terminateWorkers.load(std::memory_order_relaxed); - } while (!canWake); - } - auto nextFiber() -> std::optional<NextFiberResult>; public: