From 6713a1028a3d18b025e2588092a9418077a88a4b Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Wed, 6 Oct 2021 15:14:29 +0200 Subject: [PATCH] deprecate SIMIX_is_maestro --- include/simgrid/s4u/Actor.hpp | 1 + include/simgrid/simix.h | 2 +- include/simgrid/simix.hpp | 5 +++-- src/kernel/actor/ActorImpl.cpp | 9 ++++----- src/s4u/s4u_Actor.cpp | 8 +++++++- src/s4u/s4u_Host.cpp | 4 ++-- src/simix/libsmx.cpp | 2 +- src/xbt/xbt_virtu.cpp | 6 ++++-- teshsuite/kernel/simcall-generic/blocking_simcall.hpp | 2 +- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 76ba654133..935187e968 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -152,6 +152,7 @@ public: /** Returns whether or not this actor has been daemonized or not **/ bool is_daemon() const; + static bool is_maestro(); /** Retrieves the name of that actor as a C++ string */ const simgrid::xbt::string& get_name() const; diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 54a23d5f99..50f845ee99 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -32,7 +32,7 @@ XBT_ATTRIB_DEPRECATED_v333("Please use kernel::context::get_parallel_mode()") XB SIMIX_context_get_parallel_mode(); XBT_ATTRIB_DEPRECATED_v333("Please use kernel::context::set_parallel_mode()") XBT_PUBLIC void SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode); -XBT_PUBLIC int SIMIX_is_maestro(); +XBT_ATTRIB_DEPRECATED_v333("Please use Actor::is_maestro()") XBT_PUBLIC int SIMIX_is_maestro(); /********************************** Global ************************************/ /* Set some code to execute in the maestro (must be used before the engine creation) diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 49e2d4a94e..b1bd126ecc 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -7,6 +7,7 @@ #ifndef SIMGRID_SIMIX_HPP #define SIMGRID_SIMIX_HPP +#include #include #include #include @@ -46,7 +47,7 @@ template typename std::result_of_t simcall(F&& code, SimcallObser { // If we are in the maestro, we take the fast path and execute the // code directly without simcall marshalling/unmarshalling/dispatch: - if (SIMIX_is_maestro()) + if (s4u::Actor::is_maestro()) return std::forward(code)(); // If we are in the application, pass the code to the maestro which @@ -76,7 +77,7 @@ template typename std::result_of_t simcall(F&& code, SimcallObser */ template void simcall_blocking(F&& code, SimcallObserver* observer = nullptr) { - xbt_assert(not SIMIX_is_maestro(), "Cannot execute blocking call in kernel mode"); + xbt_assert(not s4u::Actor::is_maestro(), "Cannot execute blocking call in kernel mode"); // Pass the code to the maestro which executes it for us and reports the result. We use a std::future which // conveniently handles the success/failure value for us. diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 5c1d62ed24..c66cb743cd 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -521,17 +521,16 @@ void create_maestro(const std::function& code) /* needs to be public and without simcall because it is called by exceptions and logging events */ const char* SIMIX_process_self_get_name() // XBT_ATTRIB_DEPRECATED_v333 { - return SIMIX_is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname(); + return simgrid::s4u::Actor::is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname(); } /** @brief Returns the process from PID. */ -smx_actor_t SIMIX_process_from_PID(aid_t pid) // XBT_ATTRIB_DEPRECATD_v331 +smx_actor_t SIMIX_process_from_PID(aid_t pid) // XBT_ATTRIB_DEPRECATED_v331 { return simgrid::kernel::actor::ActorImpl::by_pid(pid); } -int SIMIX_is_maestro() +int SIMIX_is_maestro() // XBT_ATTRIB_DEPRECATED_v333 { - const auto* self = simgrid::kernel::actor::ActorImpl::self(); - return self == nullptr || simgrid::kernel::EngineImpl::get_instance()->is_maestro(self); + return simgrid::s4u::Actor::is_maestro(); } diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 77b3806315..19729f99c8 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -170,6 +170,12 @@ bool Actor::is_daemon() const return this->pimpl_->is_daemon(); } +bool Actor::is_maestro() +{ + const auto* self = kernel::actor::ActorImpl::self(); + return self == nullptr || kernel::EngineImpl::get_instance()->is_maestro(self); +} + const simgrid::xbt::string& Actor::get_name() const { return this->pimpl_->get_name(); @@ -285,7 +291,7 @@ namespace this_actor { */ bool is_maestro() { - return SIMIX_is_maestro(); + return Actor::is_maestro(); } void sleep_for(double duration) diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 7437ff74dd..9cb59b938a 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -725,14 +725,14 @@ void sg_host_get_actor_list(const_sg_host_t host, xbt_dynar_t whereto) sg_host_t sg_host_self() { - return SIMIX_is_maestro() ? nullptr : simgrid::kernel::actor::ActorImpl::self()->get_host(); + return simgrid::s4u::Actor::is_maestro() ? nullptr : simgrid::kernel::actor::ActorImpl::self()->get_host(); } /* needs to be public and without simcall for exceptions and logging events */ const char* sg_host_self_get_name() { const char* res = ""; - if (not SIMIX_is_maestro()) { + if (not simgrid::s4u::Actor::is_maestro()) { const simgrid::s4u::Host* host = simgrid::kernel::actor::ActorImpl::self()->get_host(); if (host != nullptr) res = host->get_cname(); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 9026d321fc..06cdf2881c 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -382,7 +382,7 @@ namespace simix { void unblock(smx_actor_t actor) { - xbt_assert(SIMIX_is_maestro()); + xbt_assert(s4u::Actor::is_maestro()); actor->simcall_answer(); } } // namespace simix diff --git a/src/xbt/xbt_virtu.cpp b/src/xbt/xbt_virtu.cpp index 7670ec2d71..e2ebd8141b 100644 --- a/src/xbt/xbt_virtu.cpp +++ b/src/xbt/xbt_virtu.cpp @@ -5,8 +5,10 @@ /* 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 +#include + #include "src/kernel/actor/ActorImpl.hpp" -#include "xbt/virtu.h" int xbt_getpid() { @@ -16,5 +18,5 @@ int xbt_getpid() const char* xbt_procname(void) { - return SIMIX_is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname(); + return simgrid::s4u::Actor::is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname(); } diff --git a/teshsuite/kernel/simcall-generic/blocking_simcall.hpp b/teshsuite/kernel/simcall-generic/blocking_simcall.hpp index 7c0f74d9dc..cee8b5c2f4 100644 --- a/teshsuite/kernel/simcall-generic/blocking_simcall.hpp +++ b/teshsuite/kernel/simcall-generic/blocking_simcall.hpp @@ -44,7 +44,7 @@ namespace simix { template auto kernel_sync(F code) -> decltype(code().get()) { using T = decltype(code().get()); - xbt_assert(not SIMIX_is_maestro(), "Cannot execute blocking call in kernel mode"); + xbt_assert(not s4u::Actor::is_maestro(), "Cannot execute blocking call in kernel mode"); auto self = kernel::actor::ActorImpl::self(); xbt::Result result; -- 2.20.1