]> 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 f78b1a8c2d913ff54346c3d0ef7f9b8e068aa124..c75ad7c49f37a750b8f16a39af63a6929f34bb6e 100644 (file)
@@ -8,11 +8,9 @@
 #include <functional>
 #include <string>
 
+#include "monitoring/instrumented_mutex.h"
 #include "port/port.h"
-#include "rocksdb/env.h"
-#ifndef NDEBUG
-#include "test_util/mock_time_env.h"
-#endif  // !NDEBUG
+#include "rocksdb/system_clock.h"
 #include "util/mutexlock.h"
 
 namespace ROCKSDB_NAMESPACE {
@@ -23,14 +21,14 @@ namespace ROCKSDB_NAMESPACE {
 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
@@ -59,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.
@@ -83,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;
         }
       }
@@ -130,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_;