Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] this_actor, wait_for and wait_until
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 21 Jul 2016 10:06:16 +0000 (12:06 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 21 Jul 2016 10:06:21 +0000 (12:06 +0200)
For consistency avec ConditionVariable and the C++ standard library.

examples/s4u/mutex/s4u_mutex.cpp
include/simgrid/s4u/actor.hpp
src/mc/Session.cpp
src/s4u/s4u_actor.cpp

index c9073e4..9910290 100644 (file)
@@ -55,7 +55,7 @@ static void master()
       simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), worker,          mutex, std::ref(result));
   }
 
       simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), worker,          mutex, std::ref(result));
   }
 
-  simgrid::s4u::this_actor::sleep(10);
+  simgrid::s4u::this_actor::sleep_for(10);
   XBT_INFO("Results is -> %d", result);
 }
 
   XBT_INFO("Results is -> %d", result);
 }
 
index 5039f84..f5de605 100644 (file)
@@ -258,13 +258,26 @@ using ActorPtr = Actor::Ptr;
 namespace this_actor {
 
   /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
 namespace this_actor {
 
   /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
-  XBT_PUBLIC(void) sleep(double duration);
+  XBT_PUBLIC(void) sleep_for(double duration);
+  XBT_PUBLIC(void) sleep_until(double timeout);
 
   template<class Rep, class Period>
 
   template<class Rep, class Period>
-  inline void sleep(std::chrono::duration<Rep, Period> duration)
+  inline void sleep_for(std::chrono::duration<Rep, Period> duration)
   {
     auto seconds = std::chrono::duration_cast<SimulationClockDuration>(duration);
   {
     auto seconds = std::chrono::duration_cast<SimulationClockDuration>(duration);
-    sleep(seconds.count());
+    this_actor::sleep_for(seconds.count());
+  }
+  template<class Duration>
+  inline void sleep_until(const SimulationTimePoint<Duration>& timeout_time)
+  {
+    auto timeout_native = std::chrono::time_point_cast<SimulationClockDuration>(timeout_time);
+    this_actor::sleep_until(timeout_native.time_since_epoch().count());
+  }
+
+  XBT_ATTRIB_DEPRECATED("Use sleep_for()")
+  inline void sleep(double duration)
+  {
+    return sleep_for(duration);
   }
 
   /** Block the actor, computing the given amount of flops */
   }
 
   /** Block the actor, computing the given amount of flops */
index ff6cef6..260edd4 100644 (file)
@@ -165,10 +165,10 @@ Session* Session::spawnv(const char *path, char *const argv[])
 }
 
 // static
 }
 
 // static
-Session* Session::spawnvp(const char *path, char *const argv[])
+Session* Session::spawnvp(const char *file, char *const argv[])
 {
   return Session::fork([&] {
 {
   return Session::fork([&] {
-    execvp(path, argv);
+    execvp(file, argv);
   });
 }
 
   });
 }
 
index 016e38e..d8ad4a2 100644 (file)
@@ -110,8 +110,17 @@ void Actor::killAll() {
 
 namespace this_actor {
 
 
 namespace this_actor {
 
-void sleep(double duration) {
-  simcall_process_sleep(duration);
+void sleep_for(double duration)
+{
+  if (duration > 0)
+    simcall_process_sleep(duration);
+}
+
+XBT_PUBLIC(void) sleep_until(double timeout)
+{
+  double now = SIMIX_get_clock();
+  if (timeout > now)
+    simcall_process_sleep(timeout - now);
 }
 
 e_smx_state_t execute(double flops) {
 }
 
 e_smx_state_t execute(double flops) {