X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c630e592bf768a21557ad91fd626ea5943449152..3f2f18b52285fde45c284ccb83610d4937c16c59:/src/s4u/s4u_Actor.cpp diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index f31600a392..fa4677e9f7 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -39,31 +39,33 @@ ActorPtr Actor::self() 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) { - return SIMIX_process_self()->init(std::move(name), host)->iface(); + smx_actor_t self = SIMIX_process_self(); + kernel::actor::ActorImpl* actor = simix::simcall([self, &name, host] { return self->init(name, host).get(); }); + return actor->ciface(); } -ActorPtr Actor::start(std::function code) +ActorPtr Actor::start(const std::function& code) { - simgrid::simix::simcall([this, code] { return this->get_impl()->start(code); }); + simgrid::simix::simcall([this, &code] { pimpl_->start(code); }); return this; } -ActorPtr Actor::create(std::string name, s4u::Host* host, std::function code) +ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function& code) { smx_actor_t self = SIMIX_process_self(); + kernel::actor::ActorImpl* actor = + simix::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); }); - simgrid::kernel::actor::ActorImpl* actor = - simgrid::simix::simcall([self, name, host, code] { return self->init(std::move(name), host)->start(code); }); - - return actor->ciface(); + return actor->iface(); } -ActorPtr Actor::create(std::string name, s4u::Host* host, const std::string& function, std::vector args) +ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function, + std::vector 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) @@ -106,7 +108,12 @@ void Actor::on_exit(int_f_pvoid_pvoid_t fun, simgrid::simix::simcall([this, fun, data] { SIMIX_process_on_exit(pimpl_, fun, data); }); } -void Actor::on_exit(std::function const fun) +void Actor::on_exit(const std::function& fun, void* data) /* deprecated */ +{ + on_exit([fun, data](bool exit) { fun(exit, data); }); +} + +void Actor::on_exit(const std::function& fun) { simgrid::simix::simcall( [this, fun] { SIMIX_process_on_exit(pimpl_, [fun](int a, void* /*data*/) { fun(a != 0); }, nullptr); }); @@ -248,12 +255,12 @@ std::unordered_map* Actor::get_properties() /** 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() @@ -431,12 +438,12 @@ void exit() simgrid::simix::simcall([actor] { actor->exit(); }); } -void on_exit(std::function const fun) +void on_exit(const std::function& fun) { SIMIX_process_self()->iface()->on_exit(fun); } -void on_exit(std::function const fun, void* data) /* deprecated */ +void on_exit(const std::function& fun, void* data) /* deprecated */ { SIMIX_process_self()->iface()->on_exit([fun, data](bool exit) { fun(exit, data); }); }