Skip to content
Snippets Groups Projects

[ScheduleOnTest] block worker thread if IO is not available

Merged Florian Fischer requested to merge aj46ezos/emper:scheduleOnTest-wo-io into master
2 files
+ 19
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 10
1
// 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));
Loading