From b4b5dfe452c3d7dd084b0241a954162412ff5ae6 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 10 Mar 2019 18:37:13 +0100 Subject: [PATCH] More references for parameters of type std::function. --- include/simgrid/s4u/Actor.hpp | 14 +++++++------- include/simgrid/s4u/Engine.hpp | 6 +++--- include/simgrid/simix.hpp | 4 ++-- include/xbt/replay.hpp | 2 +- src/mc/Session.cpp | 2 +- src/mc/Session.hpp | 2 +- src/s4u/s4u_Actor.cpp | 9 ++++----- src/s4u/s4u_Engine.cpp | 6 +++--- src/simix/ActorImpl.cpp | 7 +++---- src/simix/smx_deployment.cpp | 4 ++-- src/smpi/internals/smpi_global.cpp | 2 +- src/smpi/plugins/load_balancer/load_balancer.hpp | 2 +- src/xbt/xbt_replay.cpp | 2 +- .../s4u/activity-lifecycle/activity-lifecycle.cpp | 2 +- 14 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index f3d91d1aff..8ecbe54b30 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -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 code); + static ActorPtr create(std::string name, s4u::Host* host, const std::function& code); static ActorPtr init(std::string name, s4u::Host* host); - ActorPtr start(std::function code); + ActorPtr start(const std::function& 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 code) + XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr + createActor(const char* name, s4u::Host* host, const std::function& 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*)> code, - std::vector* args) + XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr + createActor(const char* name, s4u::Host* host, const std::function*)>& code, + std::vector* args) { return create(name, host, code, args); } diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index cc6a2a8e59..e96e696bdc 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -105,19 +105,19 @@ public: size_t get_host_count(); /** @brief Returns the list of all hosts found in the platform */ std::vector get_all_hosts(); - std::vector get_filtered_hosts(std::function filter); + std::vector get_filtered_hosts(const std::function& 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 get_all_links(); - std::vector get_filtered_links(std::function filter); + std::vector get_filtered_links(const std::function& 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 get_all_actors(); - std::vector get_filtered_actors(std::function filter); + std::vector get_filtered_actors(const std::function& filter); size_t get_storage_count(); std::vector get_all_storages(); diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index beefa0c127..fd9e4a91d6 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -74,7 +74,7 @@ typedef std::function ActorCode; // Create an ActorCode based on a std::string typedef std::function 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 TimerQelt; static boost::heap::fibonacci_heap>> 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* properties); XBT_PUBLIC smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task callback); diff --git a/include/xbt/replay.hpp b/include/xbt/replay.hpp index b685b046b7..f612332d78 100644 --- a/include/xbt/replay.hpp +++ b/include/xbt/replay.hpp @@ -26,7 +26,7 @@ XBT_PUBLIC int replay_runner(const char* actor_name, const char* trace_filename) } typedef std::function 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 diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index a9279cacc4..3d62b73082 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -135,7 +135,7 @@ void Session::logState() } // static -Session* Session::fork(std::function code) +Session* Session::fork(const std::function& code) { // Create a AF_LOCAL socketpair used for exchanging messages // between the model-checker process (ourselves) and the model-checked diff --git a/src/mc/Session.hpp b/src/mc/Session.hpp index 508f65ad90..342e37cc85 100644 --- a/src/mc/Session.hpp +++ b/src/mc/Session.hpp @@ -64,7 +64,7 @@ public: * * The code is expected to `exec` the model-checker program. */ - static Session* fork(std::function code); + static Session* fork(const std::function& code); /** Spawn a model-checked process * diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index b97212a5df..6cd3ede118 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -47,16 +47,15 @@ ActorPtr Actor::init(std::string name, s4u::Host* host) return actor->ciface(); } -ActorPtr Actor::start(std::function code) +ActorPtr Actor::start(const std::function& 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 code) +ActorPtr Actor::create(std::string name, s4u::Host* host, const std::function& 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(); } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 3c8e0c5392..4e7a3f3346 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -128,7 +128,7 @@ std::vector Engine::get_all_hosts() return res; } -std::vector Engine::get_filtered_hosts(std::function filter) +std::vector Engine::get_filtered_hosts(const std::function& filter) { std::vector hosts; for (auto const& kv : pimpl->hosts_) { @@ -255,7 +255,7 @@ std::vector Engine::get_all_links() return res; } -std::vector Engine::get_filtered_links(std::function filter) +std::vector Engine::get_filtered_links(const std::function& filter) { std::vector filtered_list; for (auto const& kv : pimpl->links_) @@ -279,7 +279,7 @@ std::vector Engine::get_all_actors() return actor_list; } -std::vector Engine::get_filtered_actors(std::function filter) +std::vector Engine::get_filtered_actors(const std::function& filter) { std::vector actor_list; for (auto& kv : simix_global->process_list) { diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 984e0ec9aa..d8d4d1bf67 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -726,13 +726,12 @@ void SIMIX_process_on_exit(smx_actor_t actor, const std::function* 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(); }); } diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 71297e7862..f79f6c3653 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -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; } } diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 8f4367ce50..70def16015 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -423,7 +423,7 @@ typedef std::function 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 args) { // copy C strings, we need them writable diff --git a/src/smpi/plugins/load_balancer/load_balancer.hpp b/src/smpi/plugins/load_balancer/load_balancer.hpp index 97c1dc3547..69b2dae594 100644 --- a/src/smpi/plugins/load_balancer/load_balancer.hpp +++ b/src/smpi/plugins/load_balancer/load_balancer.hpp @@ -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 callback) + void for_each_actor(simgrid::s4u::Host* host, const std::function& callback) { auto range = host_to_actors.equal_range(host); std::for_each( diff --git a/src/xbt/xbt_replay.cpp b/src/xbt/xbt_replay.cpp index 5c7abe03a9..25d6d2c54c 100644 --- a/src/xbt/xbt_replay.cpp +++ b/src/xbt/xbt_replay.cpp @@ -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; } diff --git a/teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp b/teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp index 45e5492a68..f3737bcb1f 100644 --- a/teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp +++ b/teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp @@ -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 test) +static void run_test(const char* test_name, const std::function& test) { simgrid::s4u::Actor::create(test_name, all_hosts[0], test); simgrid::s4u::this_actor::sleep_for(10); -- 2.20.1