]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/condition_variable_debug: support mono_clock
authorKefu Chai <kchai@redhat.com>
Wed, 3 Feb 2021 16:33:36 +0000 (00:33 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 4 Feb 2021 11:26:52 +0000 (19:26 +0800)
it's allowed by the C++ standard library, there is not reason that it's
forbidden by us.

and it's important to use mono_clock along with condition_variable to
address the issue when system lock is modified when we are waiting for
an event using condition_variable::wait_until() or
condition_variable::wait_for()

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/condition_variable_debug.h
src/mon/MonClient.cc

index f094a5384f3f9a0634b57850a4760bf806cd5f54..0c5d90ac89dca48293ccfb5fa3c69a481db37322 100644 (file)
@@ -38,8 +38,17 @@ public:
   std::cv_status wait_until(
     std::unique_lock<mutex_debug>& lock,
     const std::chrono::time_point<Clock, Duration>& when) {
-    timespec ts = Clock::to_timespec(when);
-    return _wait_until(lock.mutex(), &ts);
+    if constexpr (Clock::is_steady) {
+      // convert from mono_clock to real_clock
+      auto real_when = ceph::real_clock::now();
+      const auto delta = when - Clock::now();
+      real_when += std::chrono::ceil<typename Clock::duration>(delta);
+      timespec ts = ceph::real_clock::to_timespec(real_when);
+      return _wait_until(lock.mutex(), &ts);
+    } else {
+      timespec ts = Clock::to_timespec(when);
+      return _wait_until(lock.mutex(), &ts);
+    }
   }
   template<class Rep, class Period>
   std::cv_status wait_for(
index 1e9087aff82e6582f778b1dfcdd550a3af117a13..143c389686256f761df964a7bc36fb92dba330dc 100644 (file)
@@ -567,7 +567,7 @@ int MonClient::authenticate(double timeout)
   if (!_opened())
     _reopen_session();
 
-  auto until = ceph::real_clock::now();
+  auto until = ceph::mono_clock::now();
   until += ceph::make_timespan(timeout);
   if (timeout > 0.0)
     ldout(cct, 10) << "authenticate will time out at " << until << dendl;