[Lldb-commits] [PATCH] D49713: Replace StreamTee's recursive_mutex with a normal mutex.
Raphael Isemann via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 23 18:41:15 PDT 2018
teemperor created this revision.
teemperor added a reviewer: davide.
StreamTee doesn't need a recursive_mutex so let's use a normal mutex instead.
Also gets rid of some micro-optimizations.
Still passes the test suite and the newly added unit test.
https://reviews.llvm.org/D49713
Files:
include/lldb/Utility/StreamTee.h
Index: include/lldb/Utility/StreamTee.h
===================================================================
--- include/lldb/Utility/StreamTee.h
+++ include/lldb/Utility/StreamTee.h
@@ -41,24 +41,24 @@
StreamTee(const StreamTee &rhs)
: Stream(rhs), m_streams_mutex(), m_streams() {
// Don't copy until we lock down "rhs"
- std::lock_guard<std::recursive_mutex> guard(rhs.m_streams_mutex);
+ std::lock_guard<std::mutex> guard(rhs.m_streams_mutex);
m_streams = rhs.m_streams;
}
~StreamTee() override {}
StreamTee &operator=(const StreamTee &rhs) {
if (this != &rhs) {
Stream::operator=(rhs);
- std::lock_guard<std::recursive_mutex> lhs_locker(m_streams_mutex);
- std::lock_guard<std::recursive_mutex> rhs_locker(rhs.m_streams_mutex);
+ std::lock_guard<std::mutex> lhs_locker(m_streams_mutex);
+ std::lock_guard<std::mutex> rhs_locker(rhs.m_streams_mutex);
m_streams = rhs.m_streams;
}
return *this;
}
void Flush() override {
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
collection::iterator pos, end;
for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) {
// Allow for our collection to contain NULL streams. This allows the
@@ -71,7 +71,7 @@
}
size_t Write(const void *s, size_t length) override {
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
if (m_streams.empty())
return 0;
@@ -94,31 +94,27 @@
}
size_t AppendStream(const lldb::StreamSP &stream_sp) {
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
size_t new_idx = m_streams.size();
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
m_streams.push_back(stream_sp);
return new_idx;
}
size_t GetNumStreams() const {
- size_t result = 0;
- {
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
- result = m_streams.size();
- }
- return result;
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
+ return m_streams.size();
}
lldb::StreamSP GetStreamAtIndex(uint32_t idx) {
lldb::StreamSP stream_sp;
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
if (idx < m_streams.size())
stream_sp = m_streams[idx];
return stream_sp;
}
void SetStreamAtIndex(uint32_t idx, const lldb::StreamSP &stream_sp) {
- std::lock_guard<std::recursive_mutex> guard(m_streams_mutex);
+ std::lock_guard<std::mutex> guard(m_streams_mutex);
// Resize our stream vector as necessary to fit as many streams as needed.
// This also allows this class to be used with hard coded indexes that can
// be used contain many streams, not all of which are valid.
@@ -129,7 +125,7 @@
protected:
typedef std::vector<lldb::StreamSP> collection;
- mutable std::recursive_mutex m_streams_mutex;
+ mutable std::mutex m_streams_mutex;
collection m_streams;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49713.156940.patch
Type: text/x-patch
Size: 3122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180724/eac31557/attachment.bin>
More information about the lldb-commits
mailing list