]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/OutputDataSocket: Mutex -> ceph::mutex
authorSage Weil <sage@redhat.com>
Tue, 16 Oct 2018 14:24:49 +0000 (09:24 -0500)
committerKefu Chai <kchai@redhat.com>
Wed, 21 Nov 2018 03:56:32 +0000 (11:56 +0800)
Fix race on cond wait too.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/OutputDataSocket.cc
src/common/OutputDataSocket.h

index e9d536c2d58d24abfa0ef5b646ad08443de7e276..daba820cf05a3b2a4f26e348dcc307238d35e79a 100644 (file)
  * 
  */
 
+#include <poll.h>
+#include <sys/un.h>
+#include <unistd.h>
+
 #include "common/OutputDataSocket.h"
 #include "common/errno.h"
+#include "common/debug.h"
 #include "common/safe_io.h"
 #include "include/compat.h"
 #include "include/sock_compat.h"
 
-#include <poll.h>
-#include <sys/un.h>
-
 // re-include our assert to clobber the system one; fix dout:
 #include "include/ceph_assert.h"
 
@@ -91,8 +93,7 @@ OutputDataSocket::OutputDataSocket(CephContext *cct, uint64_t _backlog)
     m_shutdown_rd_fd(-1),
     m_shutdown_wr_fd(-1),
     going_down(false),
-    data_size(0),
-    m_lock("OutputDataSocket::m_lock")
+    data_size(0)
 {
 }
 
@@ -274,15 +275,15 @@ void OutputDataSocket::handle_connection(int fd)
     return;
 
   do {
-    m_lock.lock();
-    cond.Wait(m_lock);
-
-    if (going_down) {
-      m_lock.unlock();
-      break;
+    {
+      std::unique_lock l(m_lock);
+      if (!going_down) {
+       cond.wait(l);
+      }
+      if (going_down) {
+       break;
+      }
     }
-    m_lock.unlock();
-
     ret = dump_data(fd);
   } while (ret >= 0);
 }
@@ -354,7 +355,7 @@ void OutputDataSocket::shutdown()
 {
   m_lock.lock();
   going_down = true;
-  cond.Signal();
+  cond.notify_all();
   m_lock.unlock();
 
   if (m_shutdown_wr_fd < 0)
@@ -381,7 +382,7 @@ void OutputDataSocket::shutdown()
 
 void OutputDataSocket::append_output(bufferlist& bl)
 {
-  std::lock_guard<Mutex> l(m_lock);
+  std::lock_guard l(m_lock);
 
   if (data_size + bl.length() > data_max_backlog) {
     ldout(m_cct, 20) << "dropping data output, max backlog reached" << dendl;
@@ -390,5 +391,5 @@ void OutputDataSocket::append_output(bufferlist& bl)
 
   data_size += bl.length();
 
-  cond.Signal();
+  cond.notify_all();
 }
index 0bce1ded790de82f8a2702a72fd362331b632bf5..e974d1b58c5da33a3a14e7e0ce62dc7c9b9df299 100644 (file)
@@ -15,7 +15,9 @@
 #ifndef CEPH_COMMON_OUTPUTDATASOCKET_H
 #define CEPH_COMMON_OUTPUTDATASOCKET_H
 
-#include "common/Cond.h"
+#include "common/ceph_mutex.h"
+#include "common/Thread.h"
+#include "include/buffer.h"
 
 class CephContext;
 
@@ -56,8 +58,8 @@ protected:
 
   std::list<bufferlist> data;
 
-  Mutex m_lock;
-  Cond cond;
+  ceph::mutex m_lock = ceph::make_mutex("OutputDataSocket::m_lock");
+  ceph::condition_variable cond;
 
   bufferlist delim;
 };