]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/util/repeatable_thread.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / util / repeatable_thread.h
index 34164ca562ba8ed3785207a315aade606790c1c8..967cc49945e4424c5c4f900d97801e5ee61f3395 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "port/port.h"
 #include "rocksdb/env.h"
+#include "util/mock_time_env.h"
 #include "util/mutexlock.h"
 
 namespace rocksdb {
@@ -24,6 +25,7 @@ class RepeatableThread {
         env_(env),
         delay_us_(delay_us),
         initial_delay_us_(initial_delay_us),
+        mutex_(env),
         cond_var_(&mutex_),
         running_(true),
 #ifndef NDEBUG
@@ -35,7 +37,7 @@ class RepeatableThread {
 
   void cancel() {
     {
-      MutexLock l(&mutex_);
+      InstrumentedMutexLock l(&mutex_);
       if (!running_) {
         return;
       }
@@ -45,6 +47,8 @@ class RepeatableThread {
     thread_.join();
   }
 
+  bool IsRunning() { return running_; }
+
   ~RepeatableThread() { cancel(); }
 
 #ifndef NDEBUG
@@ -55,7 +59,7 @@ class RepeatableThread {
   //
   // Note: only support one caller of this method.
   void TEST_WaitForRun(std::function<void()> callback = nullptr) {
-    MutexLock l(&mutex_);
+    InstrumentedMutexLock l(&mutex_);
     while (!waiting_) {
       cond_var_.Wait();
     }
@@ -72,7 +76,7 @@ class RepeatableThread {
 
  private:
   bool wait(uint64_t delay) {
-    MutexLock l(&mutex_);
+    InstrumentedMutexLock l(&mutex_);
     if (running_ && delay > 0) {
       uint64_t wait_until = env_->NowMicros() + delay;
 #ifndef NDEBUG
@@ -111,7 +115,7 @@ class RepeatableThread {
       function_();
 #ifndef NDEBUG
       {
-        MutexLock l(&mutex_);
+        InstrumentedMutexLock l(&mutex_);
         run_count_++;
         cond_var_.SignalAll();
       }
@@ -127,8 +131,8 @@ class RepeatableThread {
 
   // Mutex lock should be held when accessing running_, waiting_
   // and run_count_.
-  port::Mutex mutex_;
-  port::CondVar cond_var_;
+  InstrumentedMutex mutex_;
+  InstrumentedCondVar cond_var_;
   bool running_;
 #ifndef NDEBUG
   // RepeatableThread waiting for timeout.