*
* 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
*
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);
}
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();
// 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;
} // 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);
}
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
}
// 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
*
* 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
*
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();
}
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_) {
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_)
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) {
* @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();
});
}
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;
}
}
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
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(
* @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;
}
});
}
/* 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);