From df4160114a1998abd2c72b9526207d66a6f03f9b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 4 Feb 2021 00:33:36 +0800 Subject: [PATCH] common/condition_variable_debug: support mono_clock 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 --- src/common/condition_variable_debug.h | 13 +++++++++++-- src/mon/MonClient.cc | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/condition_variable_debug.h b/src/common/condition_variable_debug.h index f094a5384f3..0c5d90ac89d 100644 --- a/src/common/condition_variable_debug.h +++ b/src/common/condition_variable_debug.h @@ -38,8 +38,17 @@ public: std::cv_status wait_until( std::unique_lock& lock, const std::chrono::time_point& 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(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 std::cv_status wait_for( diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 1e9087aff82..143c3896862 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -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; -- 2.39.5