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:
cur_state(NONE),
cur_ratio(0), physical_ratio(0),
epoch_lock("OSDService::epoch_lock"),
- boot_epoch(0), up_epoch(0), bind_epoch(0),
- is_stopping_lock("OSDService::is_stopping_lock")
+ boot_epoch(0), up_epoch(0), bind_epoch(0)
#ifdef PG_DEBUG_REFS
, pgid_lock("OSDService::pgid_lock")
#endif
bool OSDService::prepare_to_stop()
{
- std::lock_guard l(is_stopping_lock);
+ std::unique_lock l(is_stopping_lock);
if (get_state() != NOT_STOPPING)
return false;
osdmap->get_epoch(),
true // request ack
));
- utime_t now = ceph_clock_now();
- utime_t timeout;
- timeout.set_from_double(now + cct->_conf->osd_mon_shutdown_timeout);
- while ((ceph_clock_now() < timeout) &&
- (get_state() != STOPPING)) {
- is_stopping_cond.WaitUntil(is_stopping_lock, timeout);
- }
+ const auto timeout = ceph::make_timespan(cct->_conf->osd_mon_shutdown_timeout);
+ is_stopping_cond.wait_for(l, timeout,
+ [this] { return get_state() == STOPPING; });
}
dout(0) << __func__ << " starting shutdown" << dendl;
set_state(STOPPING);
void OSDService::got_stop_ack()
{
- std::lock_guard l(is_stopping_lock);
+ std::scoped_lock l(is_stopping_lock);
if (get_state() == PREPARING_TO_STOP) {
dout(0) << __func__ << " starting shutdown" << dendl;
set_state(STOPPING);
- is_stopping_cond.Signal();
+ is_stopping_cond.notify_all();
} else {
dout(10) << __func__ << " ignoring msg" << dendl;
}