From 92d0af220dd1e2aef863c417d4b619f853fa46e5 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Tue, 16 Jun 2020 16:48:52 -0400 Subject: [PATCH] Make XML recording thread-safe. --- oscar/SleepLib/deviceconnection.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/oscar/SleepLib/deviceconnection.cpp b/oscar/SleepLib/deviceconnection.cpp index 397db803..e5ddcf34 100644 --- a/oscar/SleepLib/deviceconnection.cpp +++ b/oscar/SleepLib/deviceconnection.cpp @@ -30,9 +30,12 @@ public: XmlRecorder(QString & string); ~XmlRecorder(); inline QXmlStreamWriter & xml() { return *m_xml; } + inline void lock() { m_mutex.lock(); } + inline void unlock() { m_mutex.unlock(); } protected: QFile* m_file; // nullptr for non-file recordings QXmlStreamWriter* m_xml; + QMutex m_mutex; void prologue(); void epilogue(); @@ -222,7 +225,9 @@ void XmlReplayEvent::record(XmlRecorder* writer) { // Do nothing if we're not recording. if (writer != nullptr) { + writer->lock(); writer->xml() << *this; + writer->unlock(); } }