return self_context->get_actor()->iface();
}
-ActorPtr Actor::init(std::string name, s4u::Host* host)
+ActorPtr Actor::init(const std::string& name, s4u::Host* host)
{
smx_actor_t self = SIMIX_process_self();
- simgrid::kernel::actor::ActorImpl* actor =
- simgrid::simix::simcall([self, name, host] { return self->init(std::move(name), host).get(); });
- intrusive_ptr_release(actor);
+ kernel::actor::ActorImpl* actor = simix::simcall([self, &name, host] { return self->init(name, host).get(); });
return actor->ciface();
}
-ActorPtr Actor::start(std::function<void()> code)
+ActorPtr Actor::start(const std::function<void()>& code)
{
- simgrid::simix::simcall([this, code] { pimpl_->start(code); });
+ simgrid::simix::simcall([this, &code] { pimpl_->start(code); });
return this;
}
-ActorPtr Actor::create(std::string name, s4u::Host* host, std::function<void()> code)
+ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function<void()>& code)
{
- simgrid::kernel::actor::ActorImpl* actor =
- simcall_process_create(std::move(name), std::move(code), nullptr, host, nullptr);
+ smx_actor_t self = SIMIX_process_self();
+ kernel::actor::ActorImpl* actor =
+ simix::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); });
return actor->iface();
}
-ActorPtr Actor::create(std::string name, s4u::Host* host, const std::string& function, std::vector<std::string> args)
+ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function,
+ std::vector<std::string> args)
{
simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function);
- return create(std::move(name), host, factory(std::move(args)));
+ return create(name, host, factory(std::move(args)));
}
void intrusive_ptr_add_ref(Actor* actor)
simgrid::simix::simcall([this, fun, data] { SIMIX_process_on_exit(pimpl_, fun, data); });
}
-void Actor::on_exit(std::function<void(bool /*failed*/)> const fun)
+void Actor::on_exit(const std::function<void(int, void*)>& fun, void* data) /* deprecated */
+{
+ on_exit([fun, data](bool exit) { fun(exit, data); });
+}
+
+void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun)
{
simgrid::simix::simcall(
[this, fun] { SIMIX_process_on_exit(pimpl_, [fun](int a, void* /*data*/) { fun(a != 0); }, nullptr); });
/** Retrieve the property value (or nullptr if not set) */
const char* Actor::get_property(const std::string& key)
{
- return simgrid::simix::simcall([this, key] { return pimpl_->get_property(key); });
+ return simgrid::simix::simcall([this, &key] { return pimpl_->get_property(key); });
}
-void Actor::set_property(const std::string& key, std::string value)
+void Actor::set_property(const std::string& key, const std::string& value)
{
- simgrid::simix::simcall([this, key, value] { pimpl_->set_property(key, std::move(value)); });
+ simgrid::simix::simcall([this, &key, &value] { pimpl_->set_property(key, value); });
}
Actor* Actor::restart()
simgrid::simix::simcall([actor] { actor->exit(); });
}
-void on_exit(std::function<void(bool)> const fun)
+void on_exit(const std::function<void(bool)>& fun)
{
SIMIX_process_self()->iface()->on_exit(fun);
}
-void on_exit(std::function<void(int, void*)> const fun, void* data) /* deprecated */
+void on_exit(const std::function<void(int, void*)>& fun, void* data) /* deprecated */
{
SIMIX_process_self()->iface()->on_exit([fun, data](bool exit) { fun(exit, data); });
}