Enable thread-safe logging.

Thread-safe logging had been disabled because of a deadlock,
possibly due to a lock acquired during a signal handler.

This patch turns thread safe logging back on and also greatly
reduces the scope of the lock, confining it only to the code that
affects the underlying output stream, instead of all the code that
builds up the formatted log message.  this should resolve the
issue surrounding the deadlock.

llvm-svn: 236892
This commit is contained in:
Zachary Turner 2015-05-08 18:50:54 +00:00
parent 7afaed2847
commit a49c59145b
1 changed files with 16 additions and 8 deletions

View File

@ -110,10 +110,6 @@ Log::VAPrintf(const char *format, va_list args)
{
static uint32_t g_sequence_id = 0;
StreamString header;
// Enabling the thread safe logging actually deadlocks right now.
// Need to fix this at some point.
// static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive);
// Mutex::Locker locker (g_LogThreadedMutex);
// Add a sequence ID if requested
if (m_options.Test (LLDB_LOG_OPTION_PREPEND_SEQUENCE))
@ -140,16 +136,28 @@ Log::VAPrintf(const char *format, va_list args)
}
header.PrintfVarArg (format, args);
stream_sp->Printf("%s\n", header.GetData());
header.PutCString("\n");
if (m_options.Test(LLDB_LOG_OPTION_BACKTRACE))
{
std::string back_trace;
llvm::raw_string_ostream stream(back_trace);
llvm::sys::PrintStackTrace(stream);
stream_sp->PutCString(back_trace.c_str());
header.PutCString(back_trace.c_str());
}
if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE))
{
static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive);
Mutex::Locker locker(g_LogThreadedMutex);
stream_sp->PutCString(header.GetString().c_str());
stream_sp->Flush();
}
else
{
stream_sp->PutCString(header.GetString().c_str());
stream_sp->Flush();
}
stream_sp->Flush();
}
}