Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Fix compilation of ConditionVariable::wait_for(lock, duration, pred)
[simgrid.git] / include / simgrid / s4u / conditionVariable.hpp
index ec9823d..ce06ef0 100644 (file)
@@ -6,8 +6,11 @@
 #ifndef SIMGRID_S4U_COND_VARIABLE_HPP
 #define SIMGRID_S4U_COND_VARIABLE_HPP
 
-#include <simgrid/s4u/mutex.hpp>
+#include <mutex>
+#include <utility> // std::swap
 
+#include <simgrid/simix.h>
+#include <simgrid/s4u/mutex.hpp>
 
 namespace simgrid {
 namespace s4u {
@@ -47,8 +50,26 @@ public:
   /**
   * Wait functions
   */
-  void wait(Mutex *mutex);
-  void wait_for(Mutex *mutex, double time);
+  void wait(std::unique_lock<Mutex>& lock);
+  // 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_for(lock, duration);
+  }
+  // TODO,wait_until
 
   /**
   * Notify functions