From 518f95f235ccf91a7ebb529b43f5675625e9ec2f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 10 Jul 2018 00:46:14 +0200 Subject: [PATCH] partially stringify s4u::Actor --- include/simgrid/msg.h | 2 +- include/simgrid/s4u/Actor.hpp | 12 ++++++------ include/simgrid/simix.h | 2 +- include/simgrid/simix.hpp | 6 +++--- src/kernel/context/Context.hpp | 2 +- src/msg/msg_private.hpp | 2 +- src/msg/msg_process.cpp | 8 ++++---- src/s4u/s4u_Actor.cpp | 8 ++++---- src/simix/ActorImpl.cpp | 14 +++++--------- src/simix/ActorImpl.hpp | 2 +- src/simix/smx_deployment.cpp | 2 +- 11 files changed, 28 insertions(+), 32 deletions(-) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index ea93d1b409..66642ef622 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -369,7 +369,7 @@ MSG_process_get_smx_ctx(msg_process_t process); SG_END_DECL() #ifdef __cplusplus -XBT_PUBLIC msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function code, void* data, +XBT_PUBLIC msg_process_t MSG_process_create_from_stdfunc(std::string name, std::function code, void* data, msg_host_t host, std::unordered_map* properties); #endif diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 182289ad5a..65d9bd6a14 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -173,9 +173,9 @@ public: * * If the actor is restarted, the actor has a fresh copy of the function. */ - static ActorPtr create(const char* name, s4u::Host* host, std::function code); + static ActorPtr create(std::string name, s4u::Host* host, std::function code); - static ActorPtr create(const char* name, s4u::Host* host, std::function*)> code, + static ActorPtr create(std::string name, s4u::Host* host, std::function*)> code, std::vector* args) { return create(name, host, [code](std::vector* args) { code(args); }, args); @@ -191,13 +191,13 @@ public: template ::type> - static ActorPtr create(const char* name, s4u::Host* host, F code, Args... args) + static ActorPtr create(std::string name, s4u::Host* host, F code, Args... args) { return create(name, host, wrap_task(std::move(code), std::move(args)...)); } // Create actor from function name: - static ActorPtr create(const char* name, s4u::Host* host, const char* function, std::vector args); + static ActorPtr create(std::string name, s4u::Host* host, std::string function, std::vector args); // ***** Methods ***** /** This actor will be automatically terminated when the last non-daemon actor finishes **/ @@ -279,8 +279,8 @@ public: /** Retrieve the property value (or nullptr if not set) */ std::unordered_map* get_properties(); // FIXME: do not export the map, but only the keys or something - const char* get_property(const char* key); - void set_property(const char* key, const char* value); + const char* get_property(std::string key); + void set_property(std::string key, std::string value); XBT_ATTRIB_DEPRECATED_v323("Please use Actor::create()") static ActorPtr createActor( const char* name, s4u::Host* host, std::function code) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 370f11b82f..1c20d8e0c2 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -186,7 +186,7 @@ XBT_PUBLIC e_smx_state_t simcall_execution_test(smx_activity_t execution); SG_BEGIN_DECL() /* Constructor and Destructor */ #ifdef __cplusplus -XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, +XBT_PUBLIC smx_actor_t simcall_process_create(std::string name, xbt_main_func_t code, void* data, sg_host_t host, int argc, char** argv, std::unordered_map* properties); #endif diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index f2273046a0..a88cf53f9c 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*, simgrid::simix::ActorCode code, + /* name */ std::string, simgrid::simix::ActorCode code, /* userdata */ void*, /* hostname */ sg_host_t, /* props */ std::unordered_map*, @@ -98,8 +98,8 @@ 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, simgrid::simix::ActorCode code, void* data, sg_host_t host, - std::unordered_map* properties); +XBT_PUBLIC smx_actor_t simcall_process_create(std::string 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/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index 8fa974730e..dd4e482c66 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -142,6 +142,6 @@ XBT_PUBLIC int SIMIX_process_get_maxpid(); XBT_PRIVATE void SIMIX_post_create_environment(); -XBT_PRIVATE simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const char *name); +XBT_PRIVATE simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(std::string name); #endif diff --git a/src/msg/msg_private.hpp b/src/msg/msg_private.hpp index 9a98d8d438..3d752fd8b4 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, simgrid::simix::ActorCode code, void* data, +XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(std::string 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 2c6ef6346f..b3962ba422 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, simgrid::simix::ActorCode code, void* data, sg_host_t host, +smx_actor_t MSG_process_create_from_SIMIX(std::string name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties, smx_actor_t /*parent_process*/) { @@ -74,7 +74,7 @@ smx_actor_t MSG_process_create_from_SIMIX(const char* name, simgrid::simix::Acto */ msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host) { - return MSG_process_create_with_environment(name, code, data, host, 0, nullptr, nullptr); + return MSG_process_create_with_environment(name == nullptr ? "" : name, code, data, host, 0, nullptr, nullptr); } /** \ingroup m_process_management @@ -146,8 +146,8 @@ 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, simgrid::simix::ActorCode code, void* data, msg_host_t host, - std::unordered_map* properties) +msg_process_t MSG_process_create_from_stdfunc(std::string 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"); simgrid::msg::ActorExt* msgExt = new simgrid::msg::ActorExt(data); diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 42fae5407c..0e3ee32f8a 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -36,13 +36,13 @@ ActorPtr Actor::self() return self_context->process()->iface(); } -ActorPtr Actor::create(const char* name, s4u::Host* host, std::function code) +ActorPtr Actor::create(std::string name, s4u::Host* host, std::function code) { simgrid::kernel::actor::ActorImpl* actor = simcall_process_create(name, std::move(code), nullptr, host, nullptr); return actor->iface(); } -ActorPtr Actor::create(const char* name, s4u::Host* host, const char* function, std::vector args) +ActorPtr Actor::create(std::string name, s4u::Host* host, std::string function, std::vector args) { simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function); simgrid::simix::ActorCode code = factory(std::move(args)); @@ -225,12 +225,12 @@ std::unordered_map* Actor::get_properties() } /** Retrieve the property value (or nullptr if not set) */ -const char* Actor::get_property(const char* key) +const char* Actor::get_property(std::string key) { return simgrid::simix::simcall([this, key] { return pimpl_->get_property(key); }); } -void Actor::set_property(const char* key, const char* value) +void Actor::set_property(std::string key, std::string value) { simgrid::simix::simcall([this, key, value] { pimpl_->set_property(key, value); }); } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index aed56e718e..e28bbc2100 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -280,14 +280,14 @@ void SIMIX_maestro_create(void (*code)(void*), void* data) * * \return the process created */ -smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host, +smx_actor_t SIMIX_process_create(std::string name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host, std::unordered_map* properties, smx_actor_t parent_process) { - XBT_DEBUG("Start process %s on host '%s'", name, host->get_cname()); + XBT_DEBUG("Start process %s on host '%s'", name.c_str(), host->get_cname()); if (host->is_off()) { - XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, host->get_cname()); + XBT_WARN("Cannot launch process '%s' on failed host '%s'", name.c_str(), host->get_cname()); return nullptr; } @@ -776,11 +776,9 @@ void SIMIX_process_on_exit(smx_actor_t process, std::function * \param argv second argument passed to \a code * \param properties the properties of the process */ -smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc, +smx_actor_t simcall_process_create(std::string name, xbt_main_func_t code, void* data, sg_host_t host, int argc, char** argv, std::unordered_map* properties) { - if (name == nullptr) - name = ""; auto wrapped_code = simgrid::xbt::wrap_main(code, argc, argv); for (int i = 0; i != argc; ++i) xbt_free(argv[i]); @@ -789,11 +787,9 @@ 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, simgrid::simix::ActorCode code, void* data, sg_host_t host, +smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data, sg_host_t host, std::unordered_map* properties) { - if (name == nullptr) - name = ""; smx_actor_t self = SIMIX_process_self(); return simgrid::simix::simcall([name, code, data, host, properties, self] { return SIMIX_process_create(name, std::move(code), data, host, properties, self); diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 1a3c47bd0c..5c1bfcaaef 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -150,7 +150,7 @@ XBT_PUBLIC void create_maestro(std::function code); 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(std::string name, std::function code, void* data, sg_host_t host, std::unordered_map* properties, smx_actor_t parent_process); diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 79a4993317..1033c13026 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -96,7 +96,7 @@ void SIMIX_function_register_default(xbt_main_func_t code) * \param name the reference name of the function. * \return The #smx_actor_t or nullptr. */ -simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const char *name) +simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(std::string name) { xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_get_actor_code_factory."); -- 2.20.1