Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Add ConditionVariable::wait(lock, predicate)
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jun 2016 08:08:03 +0000 (10:08 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jun 2016 08:26:18 +0000 (10:26 +0200)
include/simgrid/s4u/conditionVariable.hpp

index 9c9c58a..d5b9244 100644 (file)
@@ -51,7 +51,25 @@ public:
   * Wait functions
   */
   void wait(std::unique_lock<Mutex>& lock);
-  void wait_for(std::unique_lock<Mutex>& lock, double time);
+  // TODO, return std::cv_status
+  void wait_for(std::unique_lock<Mutex>& lock, double duration);
+  // TODO, wait_until
+
+  /** Variant which takes a predice */
+  template<class P>
+  void wait(std::unique_lock<Mutex>& lock, P pred)
+  {
+    while (!pred())
+      wait(lock);
+  }
+  // TODO, return std::cv_status
+  template<class P>
+  void wait_for(std::unique_lock<Mutex>& lock, double duration, P pred)
+  {
+    while (!pred())
+      wait(lock, duration);
+  }
+  // TODO,wait_until
 
   /**
   * Notify functions