From 99ff1fc34215da3339ccd227c4f17caf8294a32f Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 18 May 2016 12:09:10 -0700 Subject: [PATCH] BackoffThrottle: wait() if past max Otherwise, we risk spinning on wait_for() with a small delay. Fixes: http://tracker.ceph.com/issues/15953 Signed-off-by: Samuel Just (cherry picked from commit 6f835726a7df5b29a96849fc1362186fd2116d9b) --- src/common/Throttle.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 14cf1ba894d91..8a52906cd5e5d 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -376,10 +376,15 @@ std::chrono::duration BackoffThrottle::get(uint64_t c) auto start = std::chrono::system_clock::now(); delay = _get_delay(c); - while ((delay > std::chrono::duration(0)) || - !((max == 0) || (current == 0) || ((current + c) <= max))) { + while (true) { + if (!((max == 0) || (current == 0) || (current + c) <= max)) { + (*ticket)->wait(l); + } else if (delay > std::chrono::duration(0)) { + (*ticket)->wait_for(l, delay); + } else { + break; + } assert(ticket == waiters.begin()); - (*ticket)->wait_for(l, delay); delay = _get_delay(c) - (std::chrono::system_clock::now() - start); } waiters.pop_front(); -- 2.39.5