trace events: fix deadlock from non-recursive mutex.

Release lock over s_pBufferFullCallback:
 #4  std::lock_guard<std::mutex>::lock_guard(std::mutex&)
 #5  comphelper::TraceEvent::getEventVectorAndClear()
 #6  0x00007f2367c61836 in comphelper::TraceEvent::getRecordingAndClear()
 #7  0x00007f236877263e in (anonymous namespace)::TraceEventDumper::flushRecordings()
 #8  0x00007f2367c60cb7 in comphelper::TraceEvent::addRecording(rtl::OUString const&)

regression from:
  commit c2424341ed
  Date:   Sun Jan 30 10:30:27 2022 +0100
    comphelper : use std::mutex in traceevent

Change-Id: Ic89d63d14f06d710937a4da759976ae308c9df45
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161329
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Michael Meeks
2023-12-28 21:57:57 +00:00
committed by Noel Grandin
parent 06fe555abb
commit d7bbd8363e

View File

@ -40,15 +40,16 @@ std::mutex g_aMutex;
void TraceEvent::addRecording(const OUString& sObject)
{
std::lock_guard aGuard(g_aMutex);
g_aRecording.emplace_back(sObject);
if (s_nBufferSize > 0 && g_aRecording.size() >= s_nBufferSize)
bool bEmitCallback;
{
if (s_pBufferFullCallback != nullptr)
(*s_pBufferFullCallback)();
std::lock_guard aGuard(g_aMutex);
g_aRecording.emplace_back(sObject);
bEmitCallback = s_nBufferSize > 0 && g_aRecording.size() >= s_nBufferSize;
}
if (bEmitCallback && s_pBufferFullCallback != nullptr)
(*s_pBufferFullCallback)();
}
void TraceEvent::addInstantEvent(const char* sName, const std::map<OUString, OUString>& args)