Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New: this_actor::isMaestro() returns whether we are in kernel mode
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 18 Jun 2017 20:14:08 +0000 (22:14 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 18 Jun 2017 20:14:08 +0000 (22:14 +0200)
ChangeLog
include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp

index 8e28aea..f903db2 100644 (file)
--- 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
 
       - 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.
  XBT
   - Replay: New function xbt_replay_action_get():
     Retrieve the function previously associated to an event type.
index 8cafe9f..5b0378c 100644 (file)
@@ -281,15 +281,16 @@ public:
  *  @brief Static methods working on the current actor (see @ref s4u::Actor) */
 namespace this_actor {
 
  *  @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<class Rep, class Period>
-  inline void sleep_for(std::chrono::duration<Rep, Period> duration)
-  {
-    auto seconds = std::chrono::duration_cast<SimulationClockDuration>(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 <class Rep, class Period> inline void sleep_for(std::chrono::duration<Rep, Period> duration)
+{
+  auto seconds = std::chrono::duration_cast<SimulationClockDuration>(duration);
+  this_actor::sleep_for(seconds.count());
   }
   template<class Duration>
   inline void sleep_until(const SimulationTimePoint<Duration>& timeout_time)
   }
   template<class Duration>
   inline void sleep_until(const SimulationTimePoint<Duration>& timeout_time)
index 6b036dd..7b6e968 100644 (file)
@@ -168,6 +168,21 @@ void Actor::setProperty(const char* key, const char* value)
 
 namespace this_actor {
 
 
 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)
 void sleep_for(double duration)
 {
   if (duration > 0)