X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_writer_local.cpp;h=5aeedac520febb823ad08e86aa10bd30a05a24ca;hb=4c4896f8490aca7f32956e402ffdf413d04c36dd;hp=e72d5c085a1454f279ff03fcb32e0428171ec2fd;hpb=d677135633f83e5eb7766839ebf4ba79677b98d2;p=apitrace diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index e72d5c0..5aeedac 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" @@ -89,7 +89,11 @@ LocalWriter::open(void) { #endif process.trimDirectory(); - os::String prefix = os::getCurrentDir(); +#ifdef ANDROID + os::String prefix = "/data"; +#else + os::String prefix = os::getCurrentDir(); +#endif prefix.join(process); for (;;) { @@ -128,7 +132,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 +156,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,16 +168,17 @@ 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. */ - os::acquireMutex(); + mutex.lock(); if (acquired) { os::log("apitrace: ignoring exception while tracing\n"); } else { @@ -184,7 +189,7 @@ void LocalWriter::flush(void) { } --acquired; } - os::releaseMutex(); + mutex.unlock(); }