From 26fdbccad6aa5c3f2741855d2653579fc88da38e Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fischer@muhq.space>
Date: Sat, 22 Jan 2022 10:59:02 +0100
Subject: [PATCH] [ScheduleOnTest] block worker thread if IO is not available

The alpha fiber waits to ensure the worker threads are suspended before
starting to schedule work on specific threads.
emper::sleep uses an AlarmFuture and thus needs emper to be build with IO
support. If IO is not available we now just block the whole worker thread.
---
 tests/ScheduleOnTest.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/ScheduleOnTest.cpp b/tests/ScheduleOnTest.cpp
index f458a99d..6b7f5ceb 100644
--- a/tests/ScheduleOnTest.cpp
+++ b/tests/ScheduleOnTest.cpp
@@ -1,6 +1,10 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 // Copyright © 2021 Florian Fischer
+#include <chrono>
+#include <thread>
+
 #include "CountingPrivateSemaphore.hpp"
+#include "Emper.hpp"
 #include "Fiber.hpp"
 #include "Runtime.hpp"
 #include "Worker.hpp"
@@ -25,7 +29,12 @@ static void scheduleOnTest() {
 	ASSERT(runtime);
 	workerCount = runtime->getWorkerCount();
 
-	emper::sleep(1);
+	// Wait so all workers can suspend themselves
+	if constexpr (emper::IO) {
+		emper::sleep(1);
+	} else {	// We can not sleep using emper mechanisms -> block the worker thread
+		std::this_thread::sleep_for(std::chrono::seconds(1));
+	}
 
 	CPS cps(1);
 	runtime->scheduleOn(*Fiber::from([&] { runOn(cps); }), (iteration % workerCount));
-- 
GitLab