Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function: Activity::wait_until()
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Aug 2018 14:09:58 +0000 (16:09 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Aug 2018 16:42:40 +0000 (18:42 +0200)
include/simgrid/s4u/Activity.hpp
src/s4u/s4u_Activity.cpp

index cd68b0a..9906f0b 100644 (file)
@@ -62,6 +62,10 @@ public:
   /** Blocks until the activity is terminated, or until the timeout is elapsed
    *  Raises: timeout exception.*/
   virtual Activity* wait_for(double timeout) = 0;
+  /** Blocks until the activity is terminated, or until the time limit is reached
+   * Raises: timeout exception. */
+  void wait_until(double time_limit);
+
   /** Cancel that activity */
   virtual Activity* cancel() = 0;
   /** Retrieve the current state of the activity */
index 9ef1d5f..da7b040 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2006-2018. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
 
 /* 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. */
@@ -8,6 +7,7 @@
 #include "xbt/log.h"
 
 #include "simgrid/s4u/Activity.hpp"
+#include "simgrid/s4u/Engine.hpp"
 
 XBT_LOG_EXTERNAL_CATEGORY(s4u);
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
@@ -15,6 +15,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
 namespace simgrid {
 namespace s4u {
 
+void Activity::wait_until(double time_limit)
+{
+  double now = Engine::get_clock();
+  if (time_limit > now)
+    wait_for(time_limit - now);
+}
+
 double Activity::get_remaining()
 {
   return remains_;