From b4bcdaa2644fe6d9634c80bb569cc8e705fc5e9a Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Sat, 26 Feb 2022 17:39:21 +0100
Subject: [PATCH] Move dispatchLoopSleep from Runtime into Dispatcher

---
 emper/Dispatcher.cpp | 19 ++++++++++++++++++-
 emper/Dispatcher.hpp |  3 +++
 emper/Runtime.hpp    | 13 -------------
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/emper/Dispatcher.cpp b/emper/Dispatcher.cpp
index 2499cad0..af53cebe 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 60e299aa..363c7732 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 40681e9d..4fefbd51 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:
-- 
GitLab