Skip to content
Snippets Groups Projects
Commit a47be194 authored by Florian Fischer's avatar Florian Fischer
Browse files

Allow an actor to be startet from anywhere

parent 47e4158c
No related branches found
No related tags found
No related merge requests found
// 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,12 +56,19 @@ 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));
if constexpr (callerEnvironment == CallerEnvironment::EMPER) {
runtime.schedule(*actorFiber);
} else {
runtime.scheduleFromAnywhere(*actorFiber);
}
}
void startFromAnywhere() { start<CallerEnvironment::ANYWHERE>(); }
void tell(T t) { queue.put(t); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment