[Lldb-commits] [lldb] r236892 - Enable thread-safe logging.

Zachary Turner zturner at google.com
Fri May 8 11:50:55 PDT 2015


Author: zturner
Date: Fri May  8 13:50:54 2015
New Revision: 236892

URL: http://llvm.org/viewvc/llvm-project?rev=236892&view=rev
Log:
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.

Modified:
    lldb/trunk/source/Core/Log.cpp

Modified: lldb/trunk/source/Core/Log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=236892&r1=236891&r2=236892&view=diff
==============================================================================
--- lldb/trunk/source/Core/Log.cpp (original)
+++ lldb/trunk/source/Core/Log.cpp Fri May  8 13:50:54 2015
@@ -110,10 +110,6 @@ Log::VAPrintf(const char *format, va_lis
     {
         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_lis
         }
 
         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();
     }
 }
 





More information about the lldb-commits mailing list