Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't use old fashioned simcall when you don't have to
[simgrid.git] / src / s4u / s4u_Actor.cpp
index 21398a2..fa4677e 100644 (file)
@@ -10,7 +10,6 @@
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/VirtualMachine.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
-#include "src/simix/smx_host_private.hpp"
 #include "src/simix/smx_private.hpp"
 #include "src/surf/HostImpl.hpp"
 
@@ -40,18 +39,33 @@ ActorPtr Actor::self()
 
   return self_context->get_actor()->iface();
 }
+ActorPtr Actor::init(const std::string& name, s4u::Host* host)
+{
+  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(const std::function<void()>& 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)
@@ -94,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<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); });
@@ -236,12 +255,12 @@ std::unordered_map<std::string, std::string>* 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()
@@ -419,12 +438,12 @@ void exit()
   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); });
 }