From a138d21077d565562a591d21260cc3937cacdba0 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 18 Jun 2017 22:14:08 +0200 Subject: [PATCH] New: this_actor::isMaestro() returns whether we are in kernel mode --- ChangeLog | 3 +++ include/simgrid/s4u/Actor.hpp | 17 +++++++++-------- src/s4u/s4u_actor.cpp | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e28aea001..f903db2d67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,6 +53,9 @@ SimGrid (3.16) UNRELEASED - MPI_Op_commutative, MPI_Fetch_and_Op, MPI_Compare_and_swap - MPI_Rput, MPI_Rget, MPI_Raccumulate, MPI_Rget_accumulate + S4U + - New: this_actor::isMaestro() returns whether we are in kernel mode. + XBT - Replay: New function xbt_replay_action_get(): Retrieve the function previously associated to an event type. diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 8cafe9fc36..5b0378c21d 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -281,15 +281,16 @@ public: * @brief Static methods working on the current actor (see @ref s4u::Actor) */ namespace this_actor { - /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */ - XBT_PUBLIC(void) sleep_for(double duration); - XBT_PUBLIC(void) sleep_until(double timeout); +XBT_PUBLIC(bool) isMaestro(); - template - inline void sleep_for(std::chrono::duration duration) - { - auto seconds = std::chrono::duration_cast(duration); - this_actor::sleep_for(seconds.count()); +/** Block the actor sleeping for that amount of seconds (may throws hostFailure) */ +XBT_PUBLIC(void) sleep_for(double duration); +XBT_PUBLIC(void) sleep_until(double timeout); + +template inline void sleep_for(std::chrono::duration duration) +{ + auto seconds = std::chrono::duration_cast(duration); + this_actor::sleep_for(seconds.count()); } template inline void sleep_until(const SimulationTimePoint& timeout_time) diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 6b036dd349..7b6e9687ab 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -168,6 +168,21 @@ void Actor::setProperty(const char* key, const char* value) namespace this_actor { +/** Returns true if run from the kernel mode, and false if run from a real actor + * + * Everything that is run out of any actor (simulation setup before the engine is run, + * computing the model evolutions as a result to the actors' action, etc) is run in + * kernel mode, just as in any operating systems. + * + * In SimGrid, the actor in charge of doing the stuff in kernel mode is called Maestro, + * because it is the one scheduling when the others should move or wait. + */ +bool isMaestro() +{ + smx_context_t self_context = SIMIX_context_self(); + return self_context == nullptr; +} + void sleep_for(double duration) { if (duration > 0) -- 2.20.1