Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More references for parameters of type std::function.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 10 Mar 2019 17:37:13 +0000 (18:37 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 11 Mar 2019 08:18:19 +0000 (09:18 +0100)
14 files changed:
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/Engine.hpp
include/simgrid/simix.hpp
include/xbt/replay.hpp
src/mc/Session.cpp
src/mc/Session.hpp
src/s4u/s4u_Actor.cpp
src/s4u/s4u_Engine.cpp
src/simix/ActorImpl.cpp
src/simix/smx_deployment.cpp
src/smpi/internals/smpi_global.cpp
src/smpi/plugins/load_balancer/load_balancer.hpp
src/xbt/xbt_replay.cpp
teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp

index f3d91d1..8ecbe54 100644 (file)
@@ -168,9 +168,9 @@ public:
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
    */
-  static ActorPtr create(std::string name, s4u::Host* host, std::function<void()> code);
+  static ActorPtr create(std::string name, s4u::Host* host, const std::function<void()>& code);
   static ActorPtr init(std::string name, s4u::Host* host);
-  ActorPtr start(std::function<void()> code);
+  ActorPtr start(const std::function<void()>& code);
 
   /** Create an actor from a std::function
    *
@@ -301,15 +301,15 @@ public:
   XBT_ATTRIB_DEPRECATED_v325("Please use Actor::by_pid(pid).kill() instead") static void kill(aid_t pid);
 
   /** @deprecated See Actor::create() */
-  XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr createActor(
-      const char* name, s4u::Host* host, std::function<void()> code)
+  XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr
+      createActor(const char* name, s4u::Host* host, const std::function<void()>& code)
   {
     return create(name, host, code);
   }
   /** @deprecated See Actor::create() */
-  XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr createActor(
-      const char* name, s4u::Host* host, std::function<void(std::vector<std::string>*)> code,
-      std::vector<std::string>* args)
+  XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr
+      createActor(const char* name, s4u::Host* host, const std::function<void(std::vector<std::string>*)>& code,
+                  std::vector<std::string>* args)
   {
     return create(name, host, code, args);
   }
index cc6a2a8..e96e696 100644 (file)
@@ -105,19 +105,19 @@ public:
   size_t get_host_count();
   /** @brief Returns the list of all hosts found in the platform */
   std::vector<Host*> get_all_hosts();
-  std::vector<Host*> get_filtered_hosts(std::function<bool(Host*)> filter);
+  std::vector<Host*> get_filtered_hosts(const std::function<bool(Host*)>& filter);
   simgrid::s4u::Host* host_by_name(const std::string& name);
   simgrid::s4u::Host* host_by_name_or_null(const std::string& name);
 
   size_t get_link_count();
   std::vector<Link*> get_all_links();
-  std::vector<Link*> get_filtered_links(std::function<bool(Link*)> filter);
+  std::vector<Link*> get_filtered_links(const std::function<bool(Link*)>& filter);
   simgrid::s4u::Link* link_by_name(const std::string& name);
   simgrid::s4u::Link* link_by_name_or_null(const std::string& name);
 
   size_t get_actor_count();
   std::vector<ActorPtr> get_all_actors();
-  std::vector<ActorPtr> get_filtered_actors(std::function<bool(ActorPtr)> filter);
+  std::vector<ActorPtr> get_filtered_actors(const std::function<bool(ActorPtr)>& filter);
 
   size_t get_storage_count();
   std::vector<Storage*> get_all_storages();
index beefa0c..fd9e4a9 100644 (file)
@@ -74,7 +74,7 @@ typedef std::function<void()> ActorCode;
 // Create an ActorCode based on a std::string
 typedef std::function<ActorCode(std::vector<std::string> args)> ActorCodeFactory;
 
-XBT_PUBLIC void register_function(const std::string& name, ActorCodeFactory factory);
+XBT_PUBLIC void register_function(const std::string& name, const ActorCodeFactory& factory);
 
 typedef std::pair<double, Timer*> TimerQelt;
 static boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<xbt::HeapComparator<TimerQelt>>> simix_timers;
@@ -110,7 +110,7 @@ public:
 } // namespace simix
 } // namespace simgrid
 
-XBT_PUBLIC smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data,
+XBT_PUBLIC smx_actor_t simcall_process_create(std::string name, const simgrid::simix::ActorCode& code, void* data,
                                               sg_host_t host, std::unordered_map<std::string, std::string>* properties);
 
 XBT_PUBLIC smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback);
index b685b04..f612332 100644 (file)
@@ -26,7 +26,7 @@ XBT_PUBLIC int replay_runner(const char* actor_name, const char* trace_filename)
 }
 
 typedef std::function<void(simgrid::xbt::ReplayAction&)> action_fun;
-XBT_PUBLIC void xbt_replay_action_register(const char* action_name, action_fun function);
+XBT_PUBLIC void xbt_replay_action_register(const char* action_name, const action_fun& function);
 XBT_PUBLIC action_fun xbt_replay_action_get(const char* action_name);
 
 #endif
index a9279ca..3d62b73 100644 (file)
@@ -135,7 +135,7 @@ void Session::logState()
 }
 
 // static
-Session* Session::fork(std::function<void()> code)
+Session* Session::fork(const std::function<void()>& code)
 {
   // Create a AF_LOCAL socketpair used for exchanging messages
   // between the model-checker process (ourselves) and the model-checked
index 508f65a..342e37c 100644 (file)
@@ -64,7 +64,7 @@ public:
    *
    *  The code is expected to `exec` the model-checker program.
    */
-  static Session* fork(std::function<void()> code);
+  static Session* fork(const std::function<void()>& code);
 
   /** Spawn a model-checked process
    *
index b97212a..6cd3ede 100644 (file)
@@ -47,16 +47,15 @@ ActorPtr Actor::init(std::string name, s4u::Host* host)
   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(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);
+  simgrid::kernel::actor::ActorImpl* actor = simcall_process_create(std::move(name), code, nullptr, host, nullptr);
 
   return actor->iface();
 }
index 3c8e0c5..4e7a3f3 100644 (file)
@@ -128,7 +128,7 @@ std::vector<Host*> Engine::get_all_hosts()
   return res;
 }
 
-std::vector<Host*> Engine::get_filtered_hosts(std::function<bool(Host*)> filter)
+std::vector<Host*> Engine::get_filtered_hosts(const std::function<bool(Host*)>& filter)
 {
   std::vector<Host*> hosts;
   for (auto const& kv : pimpl->hosts_) {
@@ -255,7 +255,7 @@ std::vector<Link*> Engine::get_all_links()
   return res;
 }
 
-std::vector<Link*> Engine::get_filtered_links(std::function<bool(Link*)> filter)
+std::vector<Link*> Engine::get_filtered_links(const std::function<bool(Link*)>& filter)
 {
   std::vector<Link*> filtered_list;
   for (auto const& kv : pimpl->links_)
@@ -279,7 +279,7 @@ std::vector<ActorPtr> Engine::get_all_actors()
   return actor_list;
 }
 
-std::vector<ActorPtr> Engine::get_filtered_actors(std::function<bool(ActorPtr)> filter)
+std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(ActorPtr)>& filter)
 {
   std::vector<ActorPtr> actor_list;
   for (auto& kv : simix_global->process_list) {
index 984e0ec..d8d4d1b 100644 (file)
@@ -726,13 +726,12 @@ void SIMIX_process_on_exit(smx_actor_t actor, const std::function<void(bool, voi
  * @param host where the new agent is executed.
  * @param properties the properties of the process
  */
-smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
+smx_actor_t simcall_process_create(std::string name, const simgrid::simix::ActorCode& code, void* data, sg_host_t host,
                                    std::unordered_map<std::string, std::string>* properties)
 {
   smx_actor_t self = SIMIX_process_self();
-  return simgrid::simix::simcall([name, code, data, host, properties, self] {
-    return simgrid::kernel::actor::ActorImpl::create(std::move(name), std::move(code), data, host, properties, self)
-        .get();
+  return simgrid::simix::simcall([name, &code, data, host, properties, self] {
+    return simgrid::kernel::actor::ActorImpl::create(std::move(name), code, data, host, properties, self).get();
   });
 }
 
index 71297e7..f79f6c3 100644 (file)
@@ -161,9 +161,9 @@ void SIMIX_process_set_function(const char* process_host, const char* process_fu
 namespace simgrid {
 namespace simix {
 
-void register_function(const std::string& name, ActorCodeFactory factory)
+void register_function(const std::string& name, const ActorCodeFactory& factory)
 {
-  simix_global->registered_functions[name] = std::move(factory);
+  simix_global->registered_functions[name] = factory;
 }
 
 }
index 8f4367c..70def16 100644 (file)
@@ -423,7 +423,7 @@ typedef std::function<int(int argc, char *argv[])> smpi_entry_point_type;
 typedef int (* smpi_c_entry_point_type)(int argc, char **argv);
 typedef void (*smpi_fortran_entry_point_type)();
 
-static int smpi_run_entry_point(smpi_entry_point_type entry_point, const std::string& executable_path,
+static int smpi_run_entry_point(const smpi_entry_point_type& entry_point, const std::string& executable_path,
                                 std::vector<std::string> args)
 {
   // copy C strings, we need them writable
index 97c1dc3..69b2dae 100644 (file)
@@ -45,7 +45,7 @@ public:
     return host_to_actors.count(host); // TODO This is linear in the size of the map. Maybe replace by constant lookup through another map?
   }
 
-  void for_each_actor(simgrid::s4u::Host* host, std::function<void(simgrid::s4u::ActorPtr)> callback)
+  void for_each_actor(simgrid::s4u::Host* host, const std::function<void(simgrid::s4u::ActorPtr)>& callback)
   {
     auto range = host_to_actors.equal_range(host);
     std::for_each(
index 5c7abe0..25d6d2c 100644 (file)
@@ -163,7 +163,7 @@ int replay_runner(const char* actor_name, const char* trace_filename)
  * @param action_name the reference name of the action.
  * @param function prototype given by the type: void...(const char** action)
  */
-void xbt_replay_action_register(const char* action_name, action_fun function)
+void xbt_replay_action_register(const char* action_name, const action_fun& function)
 {
   simgrid::xbt::action_funs[std::string(action_name)] = function;
 }
index 45e5492..f3737bc 100644 (file)
@@ -23,7 +23,7 @@ static void assert_exit(bool exp_failed, double duration)
   });
 }
 /* Helper function in charge of running a test and doing some sanity checks afterward */
-static void run_test(const char* test_name, std::function<void()> test)
+static void run_test(const char* test_name, const std::function<void()>& test)
 {
   simgrid::s4u::Actor::create(test_name, all_hosts[0], test);
   simgrid::s4u::this_actor::sleep_for(10);