From 736d837e88eef74f625f9de3d6bf8f1685268073 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 14 May 2010 10:44:00 -0700 Subject: [PATCH] throttle: allow large items if we're under our max Normally we stay under max, but for large items, take it as long as we're currently below max. This avoids deadlock. --- src/common/Throttle.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 4fe547c9f7d35..f05ae377018d1 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -19,14 +19,20 @@ private: cond.SignalOne(); max = m; } + bool _should_wait(uint64_t c) { + return + max && + ((c < max && count + c > max) || // normally stay under max + (c >= max && count > max)); // except for large c + } bool _wait(uint64_t c) { bool waited = false; - if (max && count + c > max) { + if (_should_wait(c)) { waiting += c; - while (max && count + c > max) { + do { waited = true; cond.Wait(lock); - } + } while (_should_wait(c)); waiting -= c; // wake up the next guy -- 2.39.5