// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
-#include <errno.h>
-#include <thread>
-
#include "common/Throttle.h"
-#include "common/dout.h"
-#include "common/ceph_context.h"
#include "common/perf_counters.h"
+// re-include our assert to clobber the system one; fix dout:
+#include "include/assert.h"
+
#define dout_subsys ceph_subsys_throttle
#undef dout_prefix
logger = b.create_perf_counters();
cct->get_perfcounters_collection()->add(logger);
- logger->set(l_throttle_max, max.read());
+ logger->set(l_throttle_max, max);
}
}
void Throttle::_reset_max(int64_t m)
{
assert(lock.is_locked());
- if ((int64_t)max.read() == m)
+ if (static_cast<int64_t>(max) == m)
return;
if (!cond.empty())
cond.front()->SignalOne();
if (logger)
logger->set(l_throttle_max, m);
- max.set((size_t)m);
+ max = m;
}
bool Throttle::_wait(int64_t c)
bool Throttle::wait(int64_t m)
{
- if (0 == max.read() && 0 == m) {
+ if (0 == max && 0 == m) {
return false;
}
int64_t Throttle::take(int64_t c)
{
- if (0 == max.read()) {
+ if (0 == max) {
return 0;
}
assert(c >= 0);
ldout(cct, 10) << "take " << c << dendl;
{
Mutex::Locker l(lock);
- count.add(c);
+ count += c;
}
if (logger) {
logger->inc(l_throttle_take);
logger->inc(l_throttle_take_sum, c);
- logger->set(l_throttle_val, count.read());
+ logger->set(l_throttle_val, count);
}
- return count.read();
+ return count;
}
bool Throttle::get(int64_t c, int64_t m)
{
- if (0 == max.read() && 0 == m) {
+ if (0 == max && 0 == m) {
return false;
}
assert(c >= 0);
- ldout(cct, 10) << "get " << c << " (" << count.read() << " -> " << (count.read() + c) << ")" << dendl;
+ ldout(cct, 10) << "get " << c << " (" << count.load() << " -> " << (count.load() + c) << ")" << dendl;
if (logger) {
logger->inc(l_throttle_get_started);
}
_reset_max(m);
}
waited = _wait(c);
- count.add(c);
+ count += c;
}
if (logger) {
logger->inc(l_throttle_get);
logger->inc(l_throttle_get_sum, c);
- logger->set(l_throttle_val, count.read());
+ logger->set(l_throttle_val, count);
}
return waited;
}
*/
bool Throttle::get_or_fail(int64_t c)
{
- if (0 == max.read()) {
+ if (0 == max) {
return true;
}
}
return false;
} else {
- ldout(cct, 10) << "get_or_fail " << c << " success (" << count.read() << " -> " << (count.read() + c) << ")" << dendl;
- count.add(c);
+ ldout(cct, 10) << "get_or_fail " << c << " success (" << count.load() << " -> " << (count.load() + c) << ")" << dendl;
+ count += c;
if (logger) {
logger->inc(l_throttle_get_or_fail_success);
logger->inc(l_throttle_get);
logger->inc(l_throttle_get_sum, c);
- logger->set(l_throttle_val, count.read());
+ logger->set(l_throttle_val, count);
}
return true;
}
int64_t Throttle::put(int64_t c)
{
- if (0 == max.read()) {
+ if (0 == max) {
return 0;
}
assert(c >= 0);
- ldout(cct, 10) << "put " << c << " (" << count.read() << " -> " << (count.read()-c) << ")" << dendl;
+ ldout(cct, 10) << "put " << c << " (" << count.load() << " -> " << (count.load()-c) << ")" << dendl;
Mutex::Locker l(lock);
if (c) {
if (!cond.empty())
cond.front()->SignalOne();
- assert(((int64_t)count.read()) >= c); //if count goes negative, we failed somewhere!
- count.sub(c);
+ assert(static_cast<int64_t>(count) >= c); // if count goes negative, we failed somewhere!
+ count -= c;
if (logger) {
logger->inc(l_throttle_put);
logger->inc(l_throttle_put_sum, c);
- logger->set(l_throttle_val, count.read());
+ logger->set(l_throttle_val, count);
}
}
- return count.read();
+ return count;
}
void Throttle::reset()
Mutex::Locker l(lock);
if (!cond.empty())
cond.front()->SignalOne();
- count.set(0);
+ count = 0;
if (logger) {
logger->set(l_throttle_val, 0);
}