]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlockDevice: use std::mutex and std::condition_variable
authorSage Weil <sage@redhat.com>
Fri, 5 Feb 2016 16:20:15 +0000 (11:20 -0500)
committerSage Weil <sage@redhat.com>
Mon, 8 Feb 2016 14:53:19 +0000 (09:53 -0500)
Pull aio wait code into an IOContext method too.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlockDevice.cc
src/os/bluestore/BlockDevice.h
src/os/bluestore/KernelDevice.cc

index ac17b6494cbe7e4660a0dbc53950a63ba88f6eba..f683f6fa60585e83853627a76991b8c1a8197b0d 100644 (file)
 
 void IOContext::aio_wait()
 {
-  Mutex::Locker l(lock);
+  std::unique_lock<std::mutex> l(lock);
   // see _aio_thread for waker logic
   num_waiting.inc();
   while (num_running.read() > 0 || num_reading.read() > 0) {
     dout(10) << __func__ << " " << this
             << " waiting for " << num_running.read() << " aios and/or "
             << num_reading.read() << " readers to complete" << dendl;
-    cond.Wait(lock);
+    cond.wait(l);
   }
   num_waiting.dec();
   dout(20) << __func__ << " " << this << " done" << dendl;
@@ -68,7 +68,7 @@ BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cb
 
 void BlockDevice::queue_reap_ioc(IOContext *ioc)
 {
-  Mutex::Locker l(ioc_reap_lock);
+  std::lock_guard<std::mutex> l(ioc_reap_lock);
   if (ioc_reap_count.read() == 0)
     ioc_reap_count.inc();
   ioc_reap_queue.push_back(ioc);
@@ -77,7 +77,7 @@ void BlockDevice::queue_reap_ioc(IOContext *ioc)
 void BlockDevice::reap_ioc()
 {
   if (ioc_reap_count.read()) {
-    Mutex::Locker l(ioc_reap_lock);
+    std::lock_guard<std::mutex> l(ioc_reap_lock);
     for (auto p : ioc_reap_queue) {
       dout(20) << __func__ << " reap ioc " << p << dendl;
       delete p;
index 955f77c3ca00d97cc53bb9897ba7ccf94c2b0605..897c2d01bc6c84ee88c65e695302d8606d2661fb 100644 (file)
@@ -17,6 +17,9 @@
 #ifndef CEPH_OS_BLUESTORE_BLOCKDEVICE_H
 #define CEPH_OS_BLUESTORE_BLOCKDEVICE_H
 
+#include <mutex>
+#include <condition_variable>
+
 #include "acconfig.h"
 #include "os/fs/FS.h"
 
@@ -30,9 +33,8 @@ struct IOContext {
   void *nvme_task_last = nullptr;
 #endif
 
-  Mutex lock;
-  Cond cond;
-  //interval_set<uint64_t> blocks;  ///< blocks with aio in flight
+  std::mutex lock;
+  std::condition_variable cond;
 
   list<FS::aio_t> pending_aios;    ///< not yet submitted
   list<FS::aio_t> running_aios;    ///< submitting or submitted
@@ -42,8 +44,7 @@ struct IOContext {
   atomic_t num_waiting;
 
   explicit IOContext(void *p)
-    : priv(p),
-      lock("IOContext::lock")
+    : priv(p)
     {}
 
   // no copying
@@ -51,22 +52,29 @@ struct IOContext {
   IOContext &operator=(const IOContext& other);
 
   bool has_aios() {
-    Mutex::Locker l(lock);
+    std::lock_guard<std::mutex> l(lock);
     return num_pending.read() || num_running.read();
   }
 
   void aio_wait();
+
+  void aio_wake() {
+    if (num_waiting.read()) {
+      std::lock_guard<std::mutex> l(lock);
+      cond.notify_all();
+    }
+  }
 };
 
 
 class BlockDevice {
-  Mutex ioc_reap_lock;
+  std::mutex ioc_reap_lock;
   vector<IOContext*> ioc_reap_queue;
   atomic_t ioc_reap_count;
 
 public:
-  BlockDevice(): ioc_reap_lock("BlockDevice::ioc_reap_lock") {}
-  virtual ~BlockDevice() {}
+  BlockDevice() = default;
+  virtual ~BlockDevice() = default;
   typedef void (*aio_callback_t)(void *handle, void *aio);
 
   static BlockDevice *create(
index b85b47393762cd86063375360f915b4190293879..98b71e2b73930a39481f3adf4d897ac6f654c954 100644 (file)
@@ -249,11 +249,7 @@ void KernelDevice::_aio_thread()
        if (left == 0) {
          // check waiting count before doing callback (which may
          // destroy this ioc).
-         if (ioc->num_waiting.read()) {
-           dout(20) << __func__ << " waking waiter" << dendl;
-           Mutex::Locker l(ioc->lock);
-           ioc->cond.Signal();
-         }
+         ioc->aio_wake();
          if (ioc->priv) {
            aio_callback(aio_callback_priv, ioc->priv);
          }
@@ -493,11 +489,7 @@ int KernelDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
  out:
   _aio_log_finish(ioc, off, len);
   ioc->num_reading.dec();
-  if (ioc->num_waiting.read()) {
-    dout(20) << __func__ << " waking waiter" << dendl;
-    Mutex::Locker l(ioc->lock);
-    ioc->cond.Signal();
-  }
+  ioc->aio_wake();
   return r < 0 ? r : 0;
 }