]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rbd_ggate: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jul 2019 08:31:07 +0000 (16:31 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/rbd_ggate/Server.cc
src/tools/rbd_ggate/Server.h

index 3beeec3fec0b9560e505f13e9bb83a9153cb58ce..4a38a53fe773e20aed0ba4276170829566cb433b 100644 (file)
@@ -17,7 +17,7 @@ namespace rbd {
 namespace ggate {
 
 Server::Server(Driver *drv, librbd::Image& image)
-  : m_drv(drv), m_image(image), m_lock("rbd::ggate::Server::m_lock"),
+  : m_drv(drv), m_image(image),
     m_reader_thread(this, &Server::reader_entry),
     m_writer_thread(this, &Server::writer_entry) {
 }
@@ -31,7 +31,7 @@ void Server::run() {
   dout(20) << "entering run loop" << dendl;
 
   {
-    Mutex::Locker locker(m_lock);
+    std::lock_guard locker{m_lock};
     while (!m_stopping) {
       m_cond.WaitInterval(m_lock, utime_t(1, 0));
     }
@@ -54,7 +54,7 @@ void Server::stop() {
   dout(10) << dendl;
 
   {
-    Mutex::Locker locker(m_lock);
+    std::lock_guard locker{m_lock};
     ceph_assert(m_stopping);
   }
 
@@ -67,14 +67,14 @@ void Server::stop() {
 void Server::io_start(IOContext *ctx) {
   dout(20) << ctx << dendl;
 
-  Mutex::Locker locker(m_lock);
+  std::lock_guard locker{m_lock};
   m_io_pending.push_back(&ctx->item);
 }
 
 void Server::io_finish(IOContext *ctx) {
   dout(20) << ctx << dendl;
 
-  Mutex::Locker locker(m_lock);
+  std::lock_guard locker{m_lock};
   ceph_assert(ctx->item.is_on_list());
 
   ctx->item.remove_myself();
@@ -85,11 +85,8 @@ void Server::io_finish(IOContext *ctx) {
 Server::IOContext *Server::wait_io_finish() {
   dout(20) << dendl;
 
-  Mutex::Locker locker(m_lock);
-
-  while (m_io_finished.empty() && !m_stopping) {
-    m_cond.Wait(m_lock);
-  }
+  std::unique_lock locker{m_lock};
+  m_cond.wait(locker, [this] { return !m_io_finished.empty() || m_stopping});
 
   if (m_io_finished.empty()) {
     return nullptr;
@@ -106,7 +103,7 @@ void Server::wait_clean() {
 
   ceph_assert(!m_reader_thread.is_started());
 
-  Mutex::Locker locker(m_lock);
+  std::lock_guard locker{m_lock};
 
   while (!m_io_pending.empty()) {
     m_cond.Wait(m_lock);
@@ -167,7 +164,7 @@ void Server::reader_entry() {
       if (r != -ECANCELED) {
         derr << "recv: " << cpp_strerror(r) << dendl;
       }
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       m_stopping = true;
       m_cond.Signal();
       return;
@@ -200,7 +197,7 @@ void Server::reader_entry() {
       derr << pctx << ": invalid request command: " << pctx->req->get_cmd()
            << dendl;
       c->release();
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       m_stopping = true;
       m_cond.Signal();
       return;
@@ -226,7 +223,7 @@ void Server::writer_entry() {
     int r = m_drv->send(ctx->req);
     if (r < 0) {
       derr << ctx.get() << ": send: " << cpp_strerror(r) << dendl;
-      Mutex::Locker locker(m_lock);
+      std::lock_guard locker{m_lock};
       m_stopping = true;
       m_cond.Signal();
       return;
index 8ed4f51201093c714fcd820732a1f91b87248589..bb31b89f7afa89f31acec85d9f7cdf0ff542ced5 100644 (file)
@@ -6,8 +6,7 @@
 
 #include "include/rbd/librbd.hpp"
 #include "include/xlist.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Thread.h"
 
 namespace rbd {
@@ -56,8 +55,9 @@ private:
   Driver *m_drv;
   librbd::Image &m_image;
 
-  mutable Mutex m_lock;
-  Cond m_cond;
+  mutable ceph::mutex m_lock =
+    ceph::make_mutex("rbd::ggate::Server::m_lock");
+  ceph::condition_variable m_cond;
   bool m_stopping = false;
   ThreadHelper m_reader_thread, m_writer_thread;
   xlist<IOContext*> m_io_pending;