Commit 8a47221b authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Fix up-/downstream message names in docs

parent 665c4ff7
No preview for this file type
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
#include "caf/composable_behavior_based_actor.hpp" #include "caf/composable_behavior_based_actor.hpp"
#include "caf/prohibit_top_level_spawn_marker.hpp" #include "caf/prohibit_top_level_spawn_marker.hpp"
#include "caf/detail/spawn_fwd.hpp"
#include "caf/detail/init_fun_factory.hpp" #include "caf/detail/init_fun_factory.hpp"
#include "caf/detail/spawn_fwd.hpp"
namespace caf { namespace caf {
...@@ -502,32 +502,17 @@ public: ...@@ -502,32 +502,17 @@ public:
/// @warning must be called by thread which is about to terminate /// @warning must be called by thread which is about to terminate
void thread_terminates(); void thread_terminates();
/// @endcond
private:
template <class T>
void check_invariants() {
static_assert(!std::is_base_of<prohibit_top_level_spawn_marker, T>::value,
"This actor type cannot be spawned throught an actor system. "
"Probably you have tried to spawn a broker or opencl actor.");
}
expected<strong_actor_ptr> dyn_spawn_impl(const std::string& name,
message& args,
execution_unit* ctx,
bool check_interface,
optional<const mpi&> expected_ifs);
template <class C, spawn_options Os, class... Ts> template <class C, spawn_options Os, class... Ts>
infer_handle_from_class_t<C> infer_handle_from_class_t<C>
spawn_impl(actor_config& cfg, Ts&&... xs) { spawn_impl(actor_config& cfg, Ts&&... xs) {
static_assert(is_unbound(Os), static_assert(is_unbound(Os),
"top-level spawns cannot have monitor or link flag"); "top-level spawns cannot have monitor or link flag");
// TODO: use `if constexpr` when switching to C++17
if (has_detach_flag(Os) || std::is_base_of<blocking_actor, C>::value) if (has_detach_flag(Os) || std::is_base_of<blocking_actor, C>::value)
cfg.flags |= abstract_actor::is_detached_flag; cfg.flags |= abstract_actor::is_detached_flag;
if (has_hide_flag(Os)) if (has_hide_flag(Os))
cfg.flags |= abstract_actor::is_hidden_flag; cfg.flags |= abstract_actor::is_hidden_flag;
if (!cfg.host) if (cfg.host == nullptr)
cfg.host = dummy_execution_unit(); cfg.host = dummy_execution_unit();
CAF_SET_LOGGER_SYS(this); CAF_SET_LOGGER_SYS(this);
auto res = make_actor<C>(next_actor_id(), node(), this, auto res = make_actor<C>(next_actor_id(), node(), this,
...@@ -537,6 +522,22 @@ private: ...@@ -537,6 +522,22 @@ private:
return res; return res;
} }
/// @endcond
private:
template <class T>
void check_invariants() {
static_assert(!std::is_base_of<prohibit_top_level_spawn_marker, T>::value,
"This actor type cannot be spawned throught an actor system. "
"Probably you have tried to spawn a broker or opencl actor.");
}
expected<strong_actor_ptr> dyn_spawn_impl(const std::string& name,
message& args,
execution_unit* ctx,
bool check_interface,
optional<const mpi&> expected_ifs);
/// Sets the internal actor for dynamic spawn operations. /// Sets the internal actor for dynamic spawn operations.
inline void spawn_serv(strong_actor_ptr x) { inline void spawn_serv(strong_actor_ptr x) {
internal_actors_[internal_actor_id(atom("SpawnServ"))] = std::move(x); internal_actors_[internal_actor_id(atom("SpawnServ"))] = std::move(x);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/detail/apply_args.hpp" #include "caf/detail/apply_args.hpp"
#include "caf/detail/spawn_fwd.hpp"
#include "caf/detail/type_traits.hpp" #include "caf/detail/type_traits.hpp"
namespace caf { namespace caf {
......
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
} }
error handle(inbound_path*, downstream_msg::batch& x) override { error handle(inbound_path*, downstream_msg::batch& x) override {
CAF_LOG_TRACE(CAF_ARG(msg)); CAF_LOG_TRACE(CAF_ARG(x));
using vec_type = std::vector<input_type>; using vec_type = std::vector<input_type>;
if (x.xs.match_elements<vec_type>()) { if (x.xs.match_elements<vec_type>()) {
auto& xs = x.xs.get_as<vec_type>(0); auto& xs = x.xs.get_as<vec_type>(0);
......
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
} }
error handle(inbound_path*, downstream_msg::batch& x) override { error handle(inbound_path*, downstream_msg::batch& x) override {
CAF_LOG_TRACE(CAF_ARG(msg)); CAF_LOG_TRACE(CAF_ARG(x));
using vec_type = std::vector<output_type>; using vec_type = std::vector<output_type>;
if (x.xs.match_elements<vec_type>()) { if (x.xs.match_elements<vec_type>()) {
auto& xs = x.xs.get_as<vec_type>(0); auto& xs = x.xs.get_as<vec_type>(0);
......
...@@ -58,6 +58,11 @@ namespace caf { ...@@ -58,6 +58,11 @@ namespace caf {
/// living in an own thread or cooperatively scheduled. /// living in an own thread or cooperatively scheduled.
class local_actor : public monitorable_actor { class local_actor : public monitorable_actor {
public: public:
// -- member types -----------------------------------------------------------
/// Defines a monotonic clock suitable for measuring intervals.
using clock_type = std::chrono::steady_clock;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
local_actor(actor_config& cfg); local_actor(actor_config& cfg);
...@@ -70,6 +75,17 @@ public: ...@@ -70,6 +75,17 @@ public:
virtual void launch(execution_unit* eu, bool lazy, bool hide) = 0; virtual void launch(execution_unit* eu, bool lazy, bool hide) = 0;
// -- time -------------------------------------------------------------------
/// Returns the current time.
clock_type::time_point now() const noexcept;
/// Returns the difference between `t0` and `t1`, allowing the clock to
/// return any arbitrary value depending on the measurement that took place.
clock_type::duration difference(atom_value measurement,
clock_type::time_point t0,
clock_type::time_point t1);
// -- timeout management ----------------------------------------------------- // -- timeout management -----------------------------------------------------
/// Requests a new timeout for `mid`. /// Requests a new timeout for `mid`.
......
...@@ -33,8 +33,12 @@ std::string to_string(const actor_config& x) { ...@@ -33,8 +33,12 @@ std::string to_string(const actor_config& x) {
// Note: x.groups is an input range. Traversing it is emptying it, hence we // Note: x.groups is an input range. Traversing it is emptying it, hence we
// cannot look inside the range here. // cannot look inside the range here.
std::string result = "actor_config("; std::string result = "actor_config(";
bool first = false;
auto add = [&](int flag, const char* name) { auto add = [&](int flag, const char* name) {
if ((x.flags & flag) != 0) { if ((x.flags & flag) != 0) {
if (first)
first = false;
else
result += ", "; result += ", ";
result += name; result += name;
} }
......
...@@ -408,7 +408,6 @@ actor_clock& actor_system::clock() noexcept { ...@@ -408,7 +408,6 @@ actor_clock& actor_system::clock() noexcept {
return scheduler().clock(); return scheduler().clock();
} }
void actor_system::inc_detached_threads() { void actor_system::inc_detached_threads() {
++detached; ++detached;
} }
......
...@@ -30,7 +30,7 @@ namespace { ...@@ -30,7 +30,7 @@ namespace {
class impl : public blocking_actor { class impl : public blocking_actor {
public: public:
impl(actor_config& cfg) : blocking_actor(cfg) { impl(actor_config& cfg) : blocking_actor(cfg) {
setf(is_detached_flag); // nop
} }
void act() override { void act() override {
...@@ -40,6 +40,14 @@ public: ...@@ -40,6 +40,14 @@ public:
const char* name() const override { const char* name() const override {
return "scoped_actor"; return "scoped_actor";
} }
void launch(execution_unit*, bool, bool hide) override {
CAF_LOG_TRACE(CAF_ARG(hide));
CAF_ASSERT(getf(is_blocking_flag));
if (!hide)
register_at_system();
initialize();
}
}; };
} // namespace <anonymous> } // namespace <anonymous>
...@@ -47,12 +55,11 @@ public: ...@@ -47,12 +55,11 @@ public:
scoped_actor::scoped_actor(actor_system& sys, bool hide) : context_(&sys) { scoped_actor::scoped_actor(actor_system& sys, bool hide) : context_(&sys) {
CAF_SET_LOGGER_SYS(&sys); CAF_SET_LOGGER_SYS(&sys);
actor_config cfg{&context_}; actor_config cfg{&context_};
self_ = make_actor<impl, strong_actor_ptr>(sys.next_actor_id(), sys.node(), if (hide)
&sys, cfg); cfg.flags |= abstract_actor::is_hidden_flag;
if (!hide) auto hdl = sys.spawn_impl<impl, no_spawn_options>(cfg);
ptr()->register_at_system(); self_ = actor_cast<strong_actor_ptr>(std::move(hdl));
prev_ = CAF_SET_AID(self_->id()); prev_ = CAF_SET_AID(self_->id());
ptr()->initialize();
} }
scoped_actor::~scoped_actor() { scoped_actor::~scoped_actor() {
......
...@@ -221,43 +221,7 @@ using mboxqueue = wdrr_fixed_multiplexed_queue<mboxpolicy, default_queue, ...@@ -221,43 +221,7 @@ using mboxqueue = wdrr_fixed_multiplexed_queue<mboxpolicy, default_queue,
umsg_queue, dmsg_queue, umsg_queue, dmsg_queue,
default_queue>; default_queue>;
// -- entity ------------------------------------------------------------------- // -- entity and mailbox visitor -----------------------------------------------
class abstract_clock {
public:
// -- member types -----------------------------------------------------------
using time_point = std::chrono::steady_clock::time_point;
// -- constructors, destructors, and assignment operators --------------------
virtual ~abstract_clock() {
// nop
}
virtual time_point now() const noexcept = 0;
};
class fake_clock : public abstract_clock {
public:
fake_clock(time_point* global_time) : global_time_(global_time) {
// nop
}
time_point now() const noexcept override {
return *global_time_;
}
private:
time_point* global_time_;
};
class steady_clock : public abstract_clock {
public:
time_point now() const noexcept override {
return std::chrono::steady_clock::now();
}
};
class entity : public extend<local_actor, entity>::with<mixin::sender> { class entity : public extend<local_actor, entity>::with<mixin::sender> {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment