From: Sage Weil Date: Tue, 16 Oct 2018 14:24:49 +0000 (-0500) Subject: common/OutputDataSocket: Mutex -> ceph::mutex X-Git-Tag: v14.1.0~820^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f58cef09a002591a9b41ca22ab3e943e7a4060a;p=ceph.git common/OutputDataSocket: Mutex -> ceph::mutex Fix race on cond wait too. Signed-off-by: Sage Weil --- diff --git a/src/common/OutputDataSocket.cc b/src/common/OutputDataSocket.cc index e9d536c2d58d..daba820cf05a 100644 --- a/src/common/OutputDataSocket.cc +++ b/src/common/OutputDataSocket.cc @@ -12,15 +12,17 @@ * */ +#include +#include +#include + #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 -#include - // 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 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(); } diff --git a/src/common/OutputDataSocket.h b/src/common/OutputDataSocket.h index 0bce1ded790d..e974d1b58c5d 100644 --- a/src/common/OutputDataSocket.h +++ b/src/common/OutputDataSocket.h @@ -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 data; - Mutex m_lock; - Cond cond; + ceph::mutex m_lock = ceph::make_mutex("OutputDataSocket::m_lock"); + ceph::condition_variable cond; bufferlist delim; };