]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/util/repeatable_thread.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / util / repeatable_thread.h
index 967cc49945e4424c5c4f900d97801e5ee61f3395..c75ad7c49f37a750b8f16a39af63a6929f34bb6e 100644 (file)
@@ -8,24 +8,27 @@
 #include <functional>
 #include <string>
 
+#include "monitoring/instrumented_mutex.h"
 #include "port/port.h"
-#include "rocksdb/env.h"
-#include "util/mock_time_env.h"
+#include "rocksdb/system_clock.h"
 #include "util/mutexlock.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 
+// Simple wrapper around port::Thread that supports calling a callback every
+// X seconds. If you pass in 0, then it will call your callback repeatedly
+// without delay.
 class RepeatableThread {
  public:
   RepeatableThread(std::function<void()> function,
-                   const std::string& thread_name, Env* env, uint64_t delay_us,
-                   uint64_t initial_delay_us = 0)
+                   const std::string& thread_name, SystemClock* clock,
+                   uint64_t delay_us, uint64_t initial_delay_us = 0)
       : function_(function),
         thread_name_("rocksdb:" + thread_name),
-        env_(env),
+        clock_(clock),
         delay_us_(delay_us),
         initial_delay_us_(initial_delay_us),
-        mutex_(env),
+        mutex_(clock),
         cond_var_(&mutex_),
         running_(true),
 #ifndef NDEBUG
@@ -54,7 +57,7 @@ class RepeatableThread {
 #ifndef NDEBUG
   // Wait until RepeatableThread starting waiting, call the optional callback,
   // then wait for one run of RepeatableThread. Tests can use provide a
-  // custom env object to mock time, and use the callback here to bump current
+  // custom clock object to mock time, and use the callback here to bump current
   // time and trigger RepeatableThread. See repeatable_thread_test for example.
   //
   // Note: only support one caller of this method.
@@ -78,14 +81,14 @@ class RepeatableThread {
   bool wait(uint64_t delay) {
     InstrumentedMutexLock l(&mutex_);
     if (running_ && delay > 0) {
-      uint64_t wait_until = env_->NowMicros() + delay;
+      uint64_t wait_until = clock_->NowMicros() + delay;
 #ifndef NDEBUG
       waiting_ = true;
       cond_var_.SignalAll();
 #endif
       while (running_) {
         cond_var_.TimedWait(wait_until);
-        if (env_->NowMicros() >= wait_until) {
+        if (clock_->NowMicros() >= wait_until) {
           break;
         }
       }
@@ -125,7 +128,7 @@ class RepeatableThread {
 
   const std::function<void()> function_;
   const std::string thread_name_;
-  Env* const env_;
+  SystemClock* clock_;
   const uint64_t delay_us_;
   const uint64_t initial_delay_us_;
 
@@ -143,4 +146,4 @@ class RepeatableThread {
   port::Thread thread_;
 };
 
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE