Commit 85bc667e authored by Dominik Charousset's avatar Dominik Charousset

Allow configs to provided mailbox factories

parent cc7f3496
...@@ -541,4 +541,8 @@ void actor_system::release_private_thread(detail::private_thread* ptr) { ...@@ -541,4 +541,8 @@ void actor_system::release_private_thread(detail::private_thread* ptr) {
private_threads_.release(ptr); private_threads_.release(ptr);
} }
detail::mailbox_factory* actor_system::mailbox_factory() {
return cfg_.mailbox_factory();
}
} // namespace caf } // namespace caf
...@@ -398,6 +398,7 @@ public: ...@@ -398,6 +398,7 @@ public:
infer_handle_from_class_t<C> spawn(Ts&&... xs) { infer_handle_from_class_t<C> spawn(Ts&&... xs) {
check_invariants<C>(); check_invariants<C>();
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_impl<C, Os>(cfg, detail::spawn_fwd<Ts>(xs)...); return spawn_impl<C, Os>(cfg, detail::spawn_fwd<Ts>(xs)...);
} }
...@@ -436,6 +437,7 @@ public: ...@@ -436,6 +437,7 @@ public:
static_assert(spawnable, static_assert(spawnable,
"cannot spawn function-based actor with given arguments"); "cannot spawn function-based actor with given arguments");
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_functor<Os>(detail::bool_token<spawnable>{}, cfg, fun, return spawn_functor<Os>(detail::bool_token<spawnable>{}, cfg, fun,
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -500,6 +502,7 @@ public: ...@@ -500,6 +502,7 @@ public:
infer_handle_from_fun_t<F> infer_handle_from_fun_t<F>
spawn_in_groups(std::initializer_list<group> gs, F fun, Ts&&... xs) { spawn_in_groups(std::initializer_list<group> gs, F fun, Ts&&... xs) {
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_fun_in_groups<Os>(cfg, gs.begin(), gs.end(), fun, return spawn_fun_in_groups<Os>(cfg, gs.begin(), gs.end(), fun,
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -508,6 +511,7 @@ public: ...@@ -508,6 +511,7 @@ public:
template <spawn_options Os = no_spawn_options, class Gs, class F, class... Ts> template <spawn_options Os = no_spawn_options, class Gs, class F, class... Ts>
infer_handle_from_fun_t<F> spawn_in_groups(const Gs& gs, F fun, Ts&&... xs) { infer_handle_from_fun_t<F> spawn_in_groups(const Gs& gs, F fun, Ts&&... xs) {
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_fun_in_groups<Os>(cfg, gs.begin(), gs.end(), fun, return spawn_fun_in_groups<Os>(cfg, gs.begin(), gs.end(), fun,
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -524,6 +528,7 @@ public: ...@@ -524,6 +528,7 @@ public:
infer_handle_from_class_t<T> infer_handle_from_class_t<T>
spawn_in_groups(std::initializer_list<group> gs, Ts&&... xs) { spawn_in_groups(std::initializer_list<group> gs, Ts&&... xs) {
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_class_in_groups<T, Os>(cfg, gs.begin(), gs.end(), return spawn_class_in_groups<T, Os>(cfg, gs.begin(), gs.end(),
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -532,6 +537,7 @@ public: ...@@ -532,6 +537,7 @@ public:
template <class T, spawn_options Os = no_spawn_options, class Gs, class... Ts> template <class T, spawn_options Os = no_spawn_options, class Gs, class... Ts>
infer_handle_from_class_t<T> spawn_in_groups(const Gs& gs, Ts&&... xs) { infer_handle_from_class_t<T> spawn_in_groups(const Gs& gs, Ts&&... xs) {
actor_config cfg; actor_config cfg;
cfg.mbox_factory = mailbox_factory();
return spawn_class_in_groups<T, Os>(cfg, gs.begin(), gs.end(), return spawn_class_in_groups<T, Os>(cfg, gs.begin(), gs.end(),
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -696,6 +702,7 @@ public: ...@@ -696,6 +702,7 @@ public:
"only scheduled actors may get spawned inactively"); "only scheduled actors may get spawned inactively");
CAF_SET_LOGGER_SYS(this); CAF_SET_LOGGER_SYS(this);
actor_config cfg{dummy_execution_unit(), nullptr}; actor_config cfg{dummy_execution_unit(), nullptr};
cfg.mbox_factory = mailbox_factory();
auto res = make_actor<Impl>(next_actor_id(), node(), this, cfg, auto res = make_actor<Impl>(next_actor_id(), node(), this, cfg,
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
auto ptr = static_cast<Impl*>(actor_cast<abstract_actor*>(res)); auto ptr = static_cast<Impl*>(actor_cast<abstract_actor*>(res));
...@@ -790,6 +797,8 @@ private: ...@@ -790,6 +797,8 @@ private:
config_serv_ = std::move(x); config_serv_ = std::move(x);
} }
detail::mailbox_factory* mailbox_factory();
// -- member variables ------------------------------------------------------- // -- member variables -------------------------------------------------------
/// Provides system-wide callbacks for several actor operations. /// Provides system-wide callbacks for several actor operations.
......
...@@ -478,6 +478,10 @@ actor_system_config::extract_config_file_path(string_list& args) { ...@@ -478,6 +478,10 @@ actor_system_config::extract_config_file_path(string_list& args) {
} }
} }
detail::mailbox_factory* actor_system_config::mailbox_factory() {
return nullptr;
}
const settings& content(const actor_system_config& cfg) { const settings& content(const actor_system_config& cfg) {
return cfg.content; return cfg.content;
} }
......
...@@ -32,6 +32,10 @@ namespace caf { ...@@ -32,6 +32,10 @@ namespace caf {
/// Configures an `actor_system` on startup. /// Configures an `actor_system` on startup.
class CAF_CORE_EXPORT actor_system_config { class CAF_CORE_EXPORT actor_system_config {
public: public:
// -- friends ----------------------------------------------------------------
friend class actor_system;
// -- member types ----------------------------------------------------------- // -- member types -----------------------------------------------------------
using hook_factory = std::function<io::hook*(actor_system&)>; using hook_factory = std::function<io::hook*(actor_system&)>;
...@@ -303,6 +307,8 @@ protected: ...@@ -303,6 +307,8 @@ protected:
config_option_set custom_options_; config_option_set custom_options_;
private: private:
virtual detail::mailbox_factory* mailbox_factory();
void set_remainder(string_list args); void set_remainder(string_list args);
mutable std::vector<char*> c_args_remainder_; mutable std::vector<char*> c_args_remainder_;
......
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