From 8f9f22a96a9349e7a1e2bea57ab8cd1361b93a8a Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 10 Jul 2019 00:11:38 +0200 Subject: [PATCH] fix https://framagit.org/simgrid/simgrid/issues/28 * move 2 other MSGfunctions to legacy * do not call MSG from XBT anymore --- include/simgrid/actor.h | 5 +++++ include/simgrid/msg.h | 8 ++++---- src/msg/msg_legacy.cpp | 27 +++++++++++++++++++++++++++ src/msg/msg_process.cpp | 34 ---------------------------------- src/s4u/s4u_Actor.cpp | 20 ++++++++++++++++++++ src/xbt/xbt_virtu.c | 8 +++++--- 6 files changed, 61 insertions(+), 41 deletions(-) diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index 4dddd4620c..f32860d129 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -42,6 +42,11 @@ XBT_PUBLIC void sg_actor_yield(); XBT_PUBLIC void sg_actor_sleep_for(double duration); XBT_PUBLIC sg_actor_t sg_actor_attach(const char* name, void* data, sg_host_t host, xbt_dict_t properties); XBT_PUBLIC void sg_actor_detach(); +XBT_PUBLIC sg_actor_t sg_actor_self(); +XBT_PUBLIC aid_t sg_actor_self_get_pid(); +XBT_PUBLIC aid_t sg_actor_self_get_ppid(); +XBT_PUBLIC const char* sg_actor_self_get_name(); + SG_END_DECL() #endif /* INCLUDE_SIMGRID_ACTOR_H_ */ diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 49026aca72..46b6e67943 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -235,6 +235,10 @@ XBT_PUBLIC void MSG_process_set_kill_time(msg_process_t process, double kill_tim XBT_PUBLIC void MSG_process_yield(); /*** @brief Sleep for the specified number of seconds */ XBT_PUBLIC msg_error_t MSG_process_sleep(double nb_sec); +XBT_PUBLIC msg_process_t MSG_process_self(); +XBT_PUBLIC aid_t MSG_process_self_PID(); +XBT_PUBLIC aid_t MSG_process_self_PPID(); +XBT_PUBLIC const char* MSG_process_self_name(); /** @brief Object representing an ongoing communication between processes. * @@ -320,10 +324,6 @@ 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 int MSG_process_self_PID(); -XBT_PUBLIC int MSG_process_self_PPID(); -XBT_PUBLIC const char* MSG_process_self_name(); -XBT_PUBLIC msg_process_t MSG_process_self(); XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar(); XBT_PUBLIC int MSG_process_get_number(); diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 9cedca552d..31239fe48a 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -144,6 +144,33 @@ void MSG_process_detach() { sg_actor_detach(); } +aid_t MSG_process_self_PID() +{ + return sg_actor_self_get_pid(); +} + +/** @brief Return the PPID of the current process. + * + * This function returns the PID of the parent of the currently running #msg_process_t. + */ +aid_t MSG_process_self_PPID() +{ + return sg_actor_self_get_ppid(); +} + +/** @brief Return the name of the current process. */ +const char* MSG_process_self_name() +{ + return sg_actor_self_get_name(); +} +/** @brief Return the current process. + * + * This function returns the currently running #msg_process_t. + */ +msg_process_t MSG_process_self() +{ + return sg_actor_self(); +} /* ************************** NetZones *************************** */ sg_netzone_t MSG_zone_get_root() diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index b50cdb583f..cb98064731 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -168,40 +168,6 @@ int MSG_process_get_number() return SIMIX_process_count(); } -/** @brief Return the PID of the current process. - * - * This function returns the PID of the currently running #msg_process_t. - */ -int MSG_process_self_PID() -{ - smx_actor_t self = SIMIX_process_self(); - return self == nullptr ? 0 : self->get_pid(); -} - -/** @brief Return the PPID of the current process. - * - * This function returns the PID of the parent of the currently running #msg_process_t. - */ -int MSG_process_self_PPID() -{ - return MSG_process_get_PPID(MSG_process_self()); -} - -/** @brief Return the name of the current process. */ -const char* MSG_process_self_name() -{ - return SIMIX_process_self_get_name(); -} - -/** @brief Return the current process. - * - * This function returns the currently running #msg_process_t. - */ -msg_process_t MSG_process_self() -{ - return SIMIX_process_self()->ciface(); -} - /** @brief Add a function to the list of "on_exit" functions for the current process. * The on_exit functions are the functions executed when your process is killed. * You should use them to free the data used by your process. diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 0db6b20759..26d0591eff 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -668,3 +668,23 @@ void sg_actor_detach() { simgrid::kernel::actor::ActorImpl::detach(); } + +aid_t sg_actor_self_get_pid() +{ + return simgrid::s4u::this_actor::get_pid(); +} + +aid_t sg_actor_self_get_ppid() +{ + return simgrid::s4u::this_actor::get_ppid(); +} + +const char* sg_actor_self_get_name() +{ + return simgrid::s4u::this_actor::get_cname(); +} + +sg_actor_t sg_actor_self() +{ + return simgrid::s4u::Actor::self(); +} diff --git a/src/xbt/xbt_virtu.c b/src/xbt/xbt_virtu.c index 628911fb63..9032b7820c 100644 --- a/src/xbt/xbt_virtu.c +++ b/src/xbt/xbt_virtu.c @@ -5,15 +5,17 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/msg.h" +#include "simgrid/actor.h" +#include "simgrid/simix.h" #include "xbt/virtu.h" int xbt_getpid() { - return MSG_process_self_PID(); + smx_actor_t self = SIMIX_process_self(); + return self == NULL ? 0 : sg_actor_self_get_pid(); } const char *xbt_procname(void) { - return MSG_process_self_name(); + return SIMIX_process_self_get_name(); } -- 2.20.1