Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] this_actor, wait_for and wait_until
[simgrid.git] / include / simgrid / s4u / actor.hpp
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) */
-  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>
-  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);
-    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 */