]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/Throttle.cc
update sources to v12.1.0
[ceph.git] / ceph / src / common / Throttle.cc
index 56579ca8dd18f14411ad08e1c1cb9181c253db98..7ddf4883ba8c43b4997262187758985b84a9534d 100644 (file)
@@ -1,14 +1,12 @@
 // -*- 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
@@ -59,7 +57,7 @@ Throttle::Throttle(CephContext *cct, const std::string& n, int64_t m, bool _use_
 
     logger = b.create_perf_counters();
     cct->get_perfcounters_collection()->add(logger);
-    logger->set(l_throttle_max, max.read());
+    logger->set(l_throttle_max, max);
   }
 }
 
@@ -83,13 +81,13 @@ Throttle::~Throttle()
 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)
@@ -126,7 +124,7 @@ 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;
   }
 
@@ -141,31 +139,31 @@ bool Throttle::wait(int64_t m)
 
 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);
   }
@@ -177,12 +175,12 @@ bool Throttle::get(int64_t c, int64_t m)
       _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;
 }
@@ -192,7 +190,7 @@ bool Throttle::get(int64_t c, int64_t m)
  */
 bool Throttle::get_or_fail(int64_t c)
 {
-  if (0 == max.read()) {
+  if (0 == max) {
     return true;
   }
 
@@ -205,13 +203,13 @@ bool Throttle::get_or_fail(int64_t c)
     }
     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;
   }
@@ -219,25 +217,25 @@ bool Throttle::get_or_fail(int64_t c)
 
 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()
@@ -245,7 +243,7 @@ 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);
   }