]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/tools/rbd_ggate/Server.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / tools / rbd_ggate / Server.cc
index 3beeec3fec0b9560e505f13e9bb83a9153cb58ce..2565ba10fa6f4a71e1a8248d0bffc1f77878c1ba 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,10 +31,8 @@ void Server::run() {
   dout(20) << "entering run loop" << dendl;
 
   {
-    Mutex::Locker locker(m_lock);
-    while (!m_stopping) {
-      m_cond.WaitInterval(m_lock, utime_t(1, 0));
-    }
+    std::unique_lock locker{m_lock};
+    m_cond.wait(locker, [this] { return m_stopping;});
   }
 
   dout(20) << "exiting run loop" << dendl;
@@ -54,7 +52,7 @@ void Server::stop() {
   dout(10) << dendl;
 
   {
-    Mutex::Locker locker(m_lock);
+    std::lock_guard locker{m_lock};
     ceph_assert(m_stopping);
   }
 
@@ -67,29 +65,26 @@ 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();
   m_io_finished.push_back(&ctx->item);
-  m_cond.Signal();
+  m_cond.notify_all();
 }
 
 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,11 +101,8 @@ void Server::wait_clean() {
 
   ceph_assert(!m_reader_thread.is_started());
 
-  Mutex::Locker locker(m_lock);
-
-  while (!m_io_pending.empty()) {
-    m_cond.Wait(m_lock);
-  }
+  std::unique_lock locker{m_lock};
+  m_cond.wait(locker, [this] { return m_io_pending.empty();});
 
   while (!m_io_finished.empty()) {
     std::unique_ptr<IOContext> free_ctx(m_io_finished.front());
@@ -167,9 +159,9 @@ 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();
+      m_cond.notify_all();
       return;
     }
 
@@ -200,9 +192,9 @@ 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();
+      m_cond.notify_all();
       return;
     }
   }
@@ -226,9 +218,9 @@ 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();
+      m_cond.notify_all();
       return;
     }
     dout(20) << ctx.get() << " finish" << dendl;