bool Throttle::get(int64_t c, int64_t m)
{
if (0 == max && 0 == m) {
+ count += c;
return false;
}
bool Throttle::get_or_fail(int64_t c)
{
if (0 == max) {
+ count += c;
return true;
}
int64_t Throttle::put(int64_t c)
{
if (0 == max) {
+ count -= c;
return 0;
}
uint64_t capacity,
uint64_t avg,
SafeTimer *timer,
- Mutex *timer_lock)
+ ceph::mutex *timer_lock)
: m_cct(cct), m_name(name),
m_throttle(m_cct, name + "_bucket", capacity),
m_avg(avg), m_timer(timer), m_timer_lock(timer_lock),
- m_lock(name + "_lock")
+ m_lock(ceph::make_mutex(name + "_lock"))
{}
TokenBucketThrottle::~TokenBucketThrottle() {
int TokenBucketThrottle::set_limit(uint64_t average, uint64_t burst) {
{
- std::lock_guard<Mutex> lock(m_lock);
+ std::lock_guard lock{m_lock};
if (0 < burst && burst < average) {
// the burst should never less than the average.
// The schedule period will be changed when the average rate is set.
{
- std::lock_guard<Mutex> timer_locker(*m_timer_lock);
+ std::lock_guard timer_locker{*m_timer_lock};
cancel_timer();
schedule_timer();
}
}
void TokenBucketThrottle::schedule_timer() {
- m_token_ctx = new FunctionContext(
+ m_token_ctx = new LambdaContext(
[this](int r) {
schedule_timer();
});