X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=common%2Ftrace_writer_local.cpp;h=a3ab720b2dd13f9c89536e4905ed63981ead0b2f;hb=e40a6ab0e01933c31a4e4701ea300736d7e3e32b;hp=77c8bd67de3785db908e02a7dbf574f2385f0167;hpb=5926761f1682c26266a78f2674e58beff3bfae88;p=apitrace diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index 77c8bd6..a3ab720 100644 --- a/common/trace_writer_local.cpp +++ b/common/trace_writer_local.cpp @@ -34,7 +34,7 @@ #include "os_thread.hpp" #include "os_string.hpp" #include "trace_file.hpp" -#include "trace_writer.hpp" +#include "trace_writer_local.hpp" #include "trace_format.hpp" @@ -128,7 +128,7 @@ static unsigned next_thread_id = 0; static os::thread_specific_ptr thread_id_specific_ptr; unsigned LocalWriter::beginEnter(const FunctionSig *sig) { - os::acquireMutex(); + mutex.lock(); ++acquired; if (!m_file->isOpened()) { @@ -152,11 +152,11 @@ unsigned LocalWriter::beginEnter(const FunctionSig *sig) { void LocalWriter::endEnter(void) { Writer::endEnter(); --acquired; - os::releaseMutex(); + mutex.unlock(); } void LocalWriter::beginLeave(unsigned call) { - os::acquireMutex(); + mutex.lock(); ++acquired; Writer::beginLeave(call); } @@ -164,23 +164,28 @@ void LocalWriter::beginLeave(unsigned call) { void LocalWriter::endLeave(void) { Writer::endLeave(); --acquired; - os::releaseMutex(); + mutex.unlock(); } void LocalWriter::flush(void) { /* * Do nothing if the mutex is already acquired (e.g., if a segfault happen - * while writing the file) to prevent dead-lock. + * while writing the file) as state could be inconsistent, therefore yield + * inconsistent trace files and/or repeated segfaults till infinity. */ - if (!acquired) { - os::acquireMutex(); + mutex.lock(); + if (acquired) { + os::log("apitrace: ignoring exception while tracing\n"); + } else { + ++acquired; if (m_file->isOpened()) { os::log("apitrace: flushing trace due to an exception\n"); m_file->flush(); } - os::releaseMutex(); + --acquired; } + mutex.unlock(); }