]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/condition_variable_debug.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / common / condition_variable_debug.h
index 3241502ff812d47e79cedf5027e517200c7495ca..f094a5384f3f9a0634b57850a4760bf806cd5f54 100644 (file)
@@ -38,7 +38,7 @@ public:
   std::cv_status wait_until(
     std::unique_lock<mutex_debug>& lock,
     const std::chrono::time_point<Clock, Duration>& when) {
-    timespec ts = when.to_timespec(when);
+    timespec ts = Clock::to_timespec(when);
     return _wait_until(lock.mutex(), &ts);
   }
   template<class Rep, class Period>
@@ -50,6 +50,21 @@ public:
     timespec ts = ceph::real_clock::to_timespec(when);
     return _wait_until(lock.mutex(), &ts);
   }
+  template<class Rep, class Period, class Pred>
+  bool wait_for(
+    std::unique_lock<mutex_debug>& lock,
+    const std::chrono::duration<Rep, Period>& awhile,
+    Pred pred) {
+    ceph::real_time when{ceph::real_clock::now()};
+    when += awhile;
+    timespec ts = ceph::real_clock::to_timespec(when);
+    while (!pred()) {
+      if ( _wait_until(lock.mutex(), &ts) == std::cv_status::timeout) {
+        return pred();
+      }
+    }
+    return true;
+  }
   void notify_one();
   void notify_all(bool sloppy = false);
 private: