Skip to content
Snippets Groups Projects
Commit 27ec583d authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Add Rutime::inRuntime() and Runtime::executeAndWait()

parent b3d17a5b
Branches
No related tags found
No related merge requests found
......@@ -56,5 +56,10 @@ public:
return currentFiber;
}
static bool isDispatchedControlFlow() {
const Fiber* fiber = getCurrentFiberPtr();
return fiber != nullptr;
}
friend ContextManager;
};
......@@ -135,3 +135,25 @@ void Runtime::printLastRuntimeStats() {
currentRuntime->printStats();
}
bool Runtime::inRuntime() {
return dispatcher.isDispatchedControlFlow();
}
void Runtime::executeAndWait(std::function<void()> f) {
if (inRuntime()) {
ABORT("Ca not use executeAndWait() from within the Runtime");
}
std::mutex fiberFinished;
fiberFinished.lock();
Fiber* fiber = Fiber::from([&] {
f();
fiberFinished.unlock();
});
schedule(*fiber);
fiberFinished.lock();
}
......@@ -113,6 +113,10 @@ public:
void printStats();
bool inRuntime();
void executeAndWait(std::function<void()> f);
friend ContextManager;
friend Scheduler;
friend Dispatcher;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment