summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/Log.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-05-08 18:50:54 +0000
committerZachary Turner <zturner@google.com>2015-05-08 18:50:54 +0000
commita49c59145ba0869036dac3c7326f00072a6569cd (patch)
tree9e0a286c551748c06421efb67ee7606e28b90e21 /lldb/source/Core/Log.cpp
parent7afaed284735aeb7157cc786dbf5d6bc35548063 (diff)
downloadbcm5719-llvm-a49c59145ba0869036dac3c7326f00072a6569cd.tar.gz
bcm5719-llvm-a49c59145ba0869036dac3c7326f00072a6569cd.zip
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
Diffstat (limited to 'lldb/source/Core/Log.cpp')
-rw-r--r--lldb/source/Core/Log.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp
index d2de299b648..692d89e1203 100644
--- a/lldb/source/Core/Log.cpp
+++ b/lldb/source/Core/Log.cpp
@@ -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();
}
}
OpenPOWER on IntegriCloud