[Libreoffice-commits] online.git: loolwsd/TraceFile.hpp
Michael Meeks
michael.meeks at collabora.com
Wed Sep 28 09:55:37 UTC 2016
loolwsd/TraceFile.hpp | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
New commits:
commit 86b36b8d6d3aa2a50f20139904cbd68828891708
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Wed Sep 28 10:39:20 2016 +0100
Don't flush and write to the deflater from different threads concurrently.
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
index 80c6bd7..3790a84 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -67,42 +67,53 @@ public:
~TraceFileWriter()
{
+ std::unique_lock<std::mutex> lock(_mutex);
+
_deflater.close();
_stream.close();
}
void writeEvent(const std::string& pId, const std::string& sessionId, const std::string& data)
{
- write(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Event));
- flush();
+ std::unique_lock<std::mutex> lock(_mutex);
+
+ writeLocked(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Event));
+ flushLocked();
}
void writeIncoming(const std::string& pId, const std::string& sessionId, const std::string& data)
{
+ std::unique_lock<std::mutex> lock(_mutex);
+
if (_filter.match(data))
{
- write(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Incoming));
+ writeLocked(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Incoming));
}
}
void writeOutgoing(const std::string& pId, const std::string& sessionId, const std::string& data)
{
+ std::unique_lock<std::mutex> lock(_mutex);
+
if (_recordOutgoing && _filter.match(data))
{
- write(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Outgoing));
+ writeLocked(pId, sessionId, data, static_cast<char>(TraceFileRecord::Direction::Outgoing));
}
}
- void flush()
+private:
+ void flushLocked()
{
+ Util::assertIsLocked(_mutex);
+
_deflater.flush();
_stream.flush();
}
-private:
- void write(const std::string& pId, const std::string& sessionId, const std::string& data, const char delim)
+ void writeLocked(const std::string& pId, const std::string& sessionId, const std::string& data, const char delim)
{
- std::unique_lock<std::mutex> lock(_mutex);
+ Util::assertIsLocked(_mutex);
+
const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - _epochStart;
if (_compress)
{
More information about the Libreoffice-commits
mailing list