Make XML recording thread-safe.

This commit is contained in:
sawinglogz 2020-06-16 16:48:52 -04:00
parent 8fbf665b89
commit 92d0af220d

View File

@ -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();
}
}