before this change, the is a racing after updating `count`, where
`count` could be updated again by another thread using this Throttle
instance. but the caller expects the value before the second mutation.
actually, the only caller which care about the return value is the
unittests in test/common/Throttle.cc. and without this change, the
ThrottleTest.get test fails randomly. almost 1 out of 5 runs fails.
after this change, the test passes after running for 256 times without
failures.
Signed-off-by: Kefu Chai <kchai@redhat.com>
ceph_assert(c >= 0);
ldout(cct, 10) << "put " << c << " (" << count.load() << " -> "
<< (count.load()-c) << ")" << dendl;
+ int64_t new_count;
{
std::lock_guard l(lock);
+ new_count = count;
if (c) {
if (!conds.empty())
conds.front().notify_one();
// if count goes negative, we failed somewhere!
ceph_assert(count >= c);
- count -= c;
+ new_count = count -= c;
}
}
if (logger) {
logger->set(l_throttle_val, count);
}
- return count;
+ return new_count;
}
void Throttle::reset()