diff --git a/emper/Emper.cpp b/emper/Emper.cpp index f4d9f6517768ca5bde27b4be55d9fc36aaa598a2..2c1c779e9f25216a3ad37e98a8abe16650d71159 100644 --- a/emper/Emper.cpp +++ b/emper/Emper.cpp @@ -2,16 +2,46 @@ // Copyright © 2020-2021 Florian Schmaus #include "Emper.hpp" +#include <cassert> #include <cerrno> #include <cstdint> #include <stdexcept> +#include <utility> #include "Common.hpp" +#include "Fiber.hpp" #include "Runtime.hpp" #include "emper-common.h" #include "emper-version.h" +#include "emper.hpp" #include "io/Future.hpp" +void async(Fiber* fiber) { + assert(fiber != nullptr); + Runtime* runtime = Runtime::getRuntime(); + runtime->schedule(*fiber); +} + +void async(Fiber::fiber_fun_t function, void* arg) { + Fiber* fiber = Fiber::from(std::move(function), arg); + async(fiber); +} + +void async(const Fiber::fiber_fun0_t& function) { + Fiber* fiber = Fiber::from(function); + async(fiber); +} + +void async(Fiber::fiber_fun_t function, void* arg, workeraffinity_t* affinity) { + Fiber* fiber = Fiber::from(std::move(function), arg, affinity); + async(fiber); +} + +void async(const Fiber::fiber_fun0_t& function, workeraffinity_t* affinity) { + Fiber* fiber = Fiber::from(function, affinity); + async(fiber); +} + namespace emper { auto getFullVersion() -> std::string { return EMPER_FULL_VERSION; } @@ -48,6 +78,11 @@ void destroy_runtime() { delete runtime; } +void yield() { + Runtime* runtime = Runtime::getRuntime(); + runtime->yield(); +} + auto sleep(unsigned int seconds) -> bool { if constexpr (!emper::IO) { DIE_MSG("sleep requires emper::io"); diff --git a/emper/include/emper.hpp b/emper/include/emper.hpp index fec6fdf6d00f2cc9b010f21b7569c2d74b139b9e..50f37a5f40aa7fdc5f7daeff3a193b752d35d21b 100644 --- a/emper/include/emper.hpp +++ b/emper/include/emper.hpp @@ -11,31 +11,15 @@ #include "Runtime.hpp" #include "SynchronizedFiber.hpp" -void async(Fiber* fiber) { - assert(fiber != nullptr); - Runtime* runtime = Runtime::getRuntime(); - runtime->schedule(*fiber); -} +void async(Fiber* fiber); -void async(Fiber::fiber_fun_t function, void* arg) { - Fiber* fiber = Fiber::from(std::move(function), arg); - async(fiber); -} +void async(Fiber::fiber_fun_t function, void* arg); -void async(const Fiber::fiber_fun0_t& function) { - Fiber* fiber = Fiber::from(function); - async(fiber); -} +void async(const Fiber::fiber_fun0_t& function); -void async(Fiber::fiber_fun_t function, void* arg, workeraffinity_t* affinity) { - Fiber* fiber = Fiber::from(std::move(function), arg, affinity); - async(fiber); -} +void async(Fiber::fiber_fun_t function, void* arg, workeraffinity_t* affinity); -void async(const Fiber::fiber_fun0_t& function, workeraffinity_t* affinity) { - Fiber* fiber = Fiber::from(function, affinity); - async(fiber); -} +void async(const Fiber::fiber_fun0_t& function, workeraffinity_t* affinity); template <typename S> void spawn(Fiber::fiber_fun_t function, void* arg, S& semaphore) { @@ -69,10 +53,7 @@ void init_runtime(workerid_t worker_count); void destroy_runtime(); -void yield() { - Runtime* runtime = Runtime::getRuntime(); - runtime->yield(); -} +void yield(); auto sleep(unsigned int seconds) -> bool;