From 7dc88f3f2d9046ce7244200bf1c1d3442a94e890 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Fri, 29 Jun 2018 11:07:48 +0200 Subject: [PATCH] [SIMIX] Move std::function to simgrid::simix::ActorCode That's a typedef for the same thing but makes the code more readable. --- include/simgrid/simix.hpp | 4 ++-- src/msg/msg_private.hpp | 2 +- src/msg/msg_process.cpp | 6 +++--- src/simix/ActorImpl.cpp | 8 ++++---- src/simix/ActorImpl.hpp | 10 +++++----- src/simix/smx_global.cpp | 2 +- src/simix/smx_host.cpp | 2 +- src/surf/sg_platf.cpp | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 06a9e30065..f2273046a0 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -90,7 +90,7 @@ XBT_PUBLIC void register_function(const char* name, ActorCodeFactory factory); * std::map* props: properties */ typedef smx_actor_t (*smx_creation_func_t)( - /* name */ const char*, std::function code, + /* name */ const char*, simgrid::simix::ActorCode code, /* userdata */ void*, /* hostname */ sg_host_t, /* props */ std::unordered_map*, @@ -98,7 +98,7 @@ typedef smx_actor_t (*smx_creation_func_t)( XBT_PUBLIC void SIMIX_function_register_process_create(smx_creation_func_t function); -XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, +XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, 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/src/msg/msg_private.hpp b/src/msg/msg_private.hpp index e9f8cfe9af..9a98d8d438 100644 --- a/src/msg/msg_private.hpp +++ b/src/msg/msg_private.hpp @@ -85,7 +85,7 @@ XBT_PUBLIC_DATA MSG_Global_t msg_global; /*************************************************************/ XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc); -XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, +XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties, smx_actor_t parent_process); diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 521170a2ef..12084ff278 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -57,7 +57,7 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor) } /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */ -smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, sg_host_t host, +smx_actor_t MSG_process_create_from_SIMIX(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties, smx_actor_t /*parent_process*/) { @@ -127,7 +127,7 @@ msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host, int argc, char **argv, xbt_dict_t properties) { - std::function function; + simgrid::simix::ActorCode function; if (code) function = simgrid::xbt::wrap_main(code, argc, static_cast(argv)); @@ -146,7 +146,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun return res; } -msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function code, void* data, msg_host_t host, +msg_process_t MSG_process_create_from_stdfunc(const char* name, simgrid::simix::ActorCode code, void* data, msg_host_t host, std::unordered_map* properties) { xbt_assert(code != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr"); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index e45266f06b..fe72f94c8e 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -247,7 +247,7 @@ smx_activity_t ActorImpl::sleep(double duration) return synchro; } -void create_maestro(std::function code) +void create_maestro(simgrid::simix::ActorCode code) { smx_actor_t maestro = nullptr; /* Create maestro process and initialize it */ @@ -257,7 +257,7 @@ void create_maestro(std::function code) maestro->setUserData(nullptr); if (not code) { - maestro->context = SIMIX_context_new(std::function(), nullptr, maestro); + maestro->context = SIMIX_context_new(simgrid::simix::ActorCode(), nullptr, maestro); } else { if (not simix_global) xbt_die("simix is not initialized, please call MSG_init first"); @@ -287,7 +287,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data) * * \return the process created */ -smx_actor_t SIMIX_process_create(const char* name, std::function code, void* data, simgrid::s4u::Host* host, +smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host, std::unordered_map* properties, smx_actor_t parent_process) { @@ -810,7 +810,7 @@ smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* return res; } -smx_actor_t simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, +smx_actor_t simcall_process_create(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties) { if (name == nullptr) diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 81c6326aad..3dd5f0cf11 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -26,14 +26,14 @@ namespace actor { class ProcessArg { public: std::string name; - std::function code; + simgrid::simix::ActorCode code; void* data = nullptr; s4u::Host* host = nullptr; double kill_time = 0.0; std::shared_ptr> properties; bool auto_restart = false; ProcessArg() = default; - explicit ProcessArg(std::string name, std::function code, void* data, s4u::Host* host, double kill_time, + explicit ProcessArg(std::string name, simgrid::simix::ActorCode code, void* data, s4u::Host* host, double kill_time, std::shared_ptr> properties, bool auto_restart) : name(name) , code(std::move(code)) @@ -74,7 +74,7 @@ public: s_smx_simcall simcall; std::vector on_exit; /* list of functions executed when the process dies */ - std::function code; + simgrid::simix::ActorCode code; smx_timer_t kill_timer = nullptr; private: @@ -129,14 +129,14 @@ typedef boost::intrusive::list> SynchroList; -XBT_PUBLIC void create_maestro(std::function code); +XBT_PUBLIC void create_maestro(simgrid::simix::ActorCode code); } } // namespace kernel } // namespace simgrid typedef simgrid::kernel::actor::ActorImpl* smx_actor_t; -XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, std::function code, void* data, sg_host_t host, +XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties, smx_actor_t parent_process); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 1291451690..bb06cae843 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -163,7 +163,7 @@ simgrid::config::Flag breakpoint{"simix/breakpoint", } } -static std::function maestro_code; +static simgrid::simix::ActorCode maestro_code; void SIMIX_set_maestro(void (*code)(void*), void* data) { #ifdef _WIN32 diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 659064092e..ecd86340d7 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -78,7 +78,7 @@ const char* sg_host_self_get_name() * The processes will only be restarted once, meaning that you will have to register the process * again to restart the process again. */ -void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function code, void* data, +void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, simgrid::simix::ActorCode code, void* data, double kill_time, std::unordered_map* properties, int auto_restart) { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index f521fd9250..7dd21c8512 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -437,7 +437,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor) bool auto_restart = actor->on_failure != simgrid::kernel::routing::ActorOnFailure::DIE; std::string actor_name = actor->args[0]; - std::function code = factory(std::move(actor->args)); + simgrid::simix::ActorCode code = factory(std::move(actor->args)); std::shared_ptr> properties(actor->properties); simgrid::kernel::actor::ProcessArg* arg = -- 2.20.1