diff --git a/emper/Actor.hpp b/emper/Actor.hpp index de36e9ac14329ac3cf4b9d0f3b495be6ce4a64b9..3839a13809d4c09e69eda4584d5a2b8710ae27c8 100644 --- a/emper/Actor.hpp +++ b/emper/Actor.hpp @@ -1,10 +1,11 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Schmaus +// Copyright © 2020 Florian Schmaus, Florian Fischer #pragma once #include <atomic> #include <chrono> +#include "CallerEnvironment.hpp" #include "Fiber.hpp" #include "UnboundedBlockingMpscQueue.hpp" @@ -55,13 +56,20 @@ class Actor { void stop() { setState(Stopped); } public: + template <CallerEnvironment callerEnvironment = CallerEnvironment::EMPER> void start() { if (state.load(std::memory_order_acquire) != Stopped) return; Fiber* actorFiber = Fiber::from(std::bind(&Actor::actorLoop, this)); - runtime.schedule(*actorFiber); + if constexpr (callerEnvironment == CallerEnvironment::EMPER) { + runtime.schedule(*actorFiber); + } else { + runtime.scheduleFromAnywhere(*actorFiber); + } } + void startFromAnywhere() { start<CallerEnvironment::ANYWHERE>(); } + void tell(T t) { queue.put(t); } void tellFromAnywhere(T t) { queue.putFromAnywhere(t); }