From b63024606c00dc186c5ed6335449bb92342c8f9c Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 1 Apr 2020 11:28:55 +0200 Subject: [PATCH] add sg_actor_list() and sg_actor_count() deprecate stuff for consistency and undynarification --- include/simgrid/actor.h | 3 +++ include/simgrid/engine.h | 2 +- include/simgrid/msg.h | 4 ++-- src/msg/msg_legacy.cpp | 4 ++-- src/msg/msg_process.cpp | 3 ++- src/s4u/s4u_Actor.cpp | 17 +++++++++++++++++ src/s4u/s4u_Engine.cpp | 3 ++- 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index b35f30de7e..e97a0bcaee 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -20,6 +20,9 @@ SG_BEGIN_DECL You should not access directly to the fields of the pointed structure, but always use the provided API to interact with actors. */ +XBT_PUBLIC size_t sg_actor_count(); +XBT_PUBLIC sg_actor_t* sg_actor_list(); + XBT_PUBLIC sg_actor_t sg_actor_create(const char* name, sg_host_t host, xbt_main_func_t code, int argc, const char* const* argv); XBT_PUBLIC sg_actor_t sg_actor_init(const char* name, sg_host_t host); diff --git a/include/simgrid/engine.h b/include/simgrid/engine.h index e1b5eb1ffc..66e74f561d 100644 --- a/include/simgrid/engine.h +++ b/include/simgrid/engine.h @@ -42,7 +42,7 @@ XBT_PUBLIC void simgrid_register_default(void (*code)(int, char**)); /** Retrieve the simulation time (in seconds) */ XBT_PUBLIC double simgrid_get_clock(); /** Retrieve the number of actors in the simulation */ -XBT_PUBLIC int simgrid_get_actor_count(); +XBT_ATTRIB_DEPRECATED_v330("Please use sg_actor_count()") XBT_PUBLIC int simgrid_get_actor_count(); /** @brief Allow other libraries to react to the --help flag, too * diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 8204478820..64cc2cb723 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -341,8 +341,8 @@ XBT_PUBLIC msg_process_t MSG_process_attach(const char* name, void* data, msg_ho XBT_PUBLIC void MSG_process_detach(); XBT_PUBLIC void MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup); -XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar(); -XBT_PUBLIC int MSG_process_get_number(); +XBT_ATTRIB_DEPRECATED_v330("Please use sg_actor_list()") XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar(); +XBT_ATTRIB_DEPRECATED_v330("Please use sg_actor_count()") XBT_PUBLIC int MSG_process_get_number(); XBT_PUBLIC void* MSG_process_get_data(const_sg_actor_t process); XBT_PUBLIC msg_error_t MSG_process_set_data(msg_process_t process, void* data); diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 26693aa738..3e25d76478 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -218,9 +218,9 @@ void MSG_process_unref(const_sg_actor_t process) sg_actor_unref(process); } /** @brief Return the current number MSG processes. */ -int MSG_process_get_number() +int MSG_process_get_number() // XBT_ATTRIB_DEPRECATED_v330 { - return simgrid_get_actor_count(); + return sg_actor_count(); } /* ************************** NetZones *************************** */ sg_netzone_t MSG_zone_get_root() diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 7b1055e38a..4432b25bcc 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -93,7 +93,8 @@ XBT_PUBLIC void MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup) } /** @brief returns a list of all currently existing processes */ -xbt_dynar_t MSG_processes_as_dynar() { +xbt_dynar_t MSG_processes_as_dynar() // XBT_ATTRIB_DEPRECATED_v330 +{ xbt_dynar_t res = xbt_dynar_new(sizeof(smx_actor_t), nullptr); for (auto const& kv : simix_global->process_list) { smx_actor_t actor = kv.second; diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 5937ec7c47..d6d6ae77cd 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -471,6 +471,23 @@ void migrate(Host* new_host) // deprecated } // namespace simgrid /* **************************** Public C interface *************************** */ +size_t sg_actor_count() +{ + return simgrid::s4u::Engine::get_instance()->get_actor_count(); +} + +sg_actor_t* sg_actor_list() +{ + simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance(); + size_t actor_count = e->get_actor_count(); + xbt_assert(actor_count > 0, "There is no actor!"); + std::vector actors = e->get_all_actors(); + + sg_actor_t* res = xbt_new(sg_actor_t, actors.size()); + for (size_t i = 0; i < actor_count; i++) + res[i] = actors[i].get(); + return res; +} sg_actor_t sg_actor_init(const char* name, sg_host_t host) { diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 8922d12cf2..c773d0e75f 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -459,7 +459,8 @@ double simgrid_get_clock() { return simgrid::s4u::Engine::get_clock(); } -int simgrid_get_actor_count() + +int simgrid_get_actor_count() // XBT_ATTRIB_DEPRECATED_v330 { return simgrid::s4u::Engine::get_instance()->get_actor_count(); } -- 2.20.1