Revert "Logging: Make sure logging machinery is in a consistent state after forking"
authorPavel Labath <labath@google.com>
Fri, 20 Oct 2017 19:44:53 +0000 (19:44 +0000)
committerPavel Labath <labath@google.com>
Fri, 20 Oct 2017 19:44:53 +0000 (19:44 +0000)
The pthread_atfork trick breaks on android, because
pthread_rwlock_unlock detects that it is not the same thread which
locked the lock. This means that the subsequent lock attempt will still
deadlock (only this time it happens deterministically instead of at
random). Reverting to find a better solution.

This reverts commit r316173.

llvm-svn: 316231

lldb/include/lldb/Utility/Log.h
lldb/include/lldb/Utility/Logging.h
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/source/Utility/Log.cpp
lldb/source/Utility/Logging.cpp

index 845ea160b25c1f4a28a6fb44ef36f9d48d4026e3..d856fc81eb0d123dca3b1d6350e9fd0baf1be9fb 100644 (file)
@@ -96,9 +96,6 @@ public:
     }
   };
 
-
-  static void Initialize();
-
   //------------------------------------------------------------------
   // Static accessors for logging channels
   //------------------------------------------------------------------
@@ -196,9 +193,6 @@ private:
   static uint32_t GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry,
                            llvm::ArrayRef<const char *> categories);
 
-  static void LockAllChannels();
-  static void UnlockAllChannels();
-
   Log(const Log &) = delete;
   void operator=(const Log &) = delete;
 };
index 2c75a3bf218b58ac78be68a413516ee2b3926f7b..865097e7c19440b5544def2f86f38ab0f8beea8b 100644 (file)
@@ -62,7 +62,7 @@ Log *GetLogIfAllCategoriesSet(uint32_t mask);
 
 Log *GetLogIfAnyCategoriesSet(uint32_t mask);
 
-void InitializeLldbChannel();
+void InitializeLog();
 
 } // namespace lldb_private
 
index 853547051ff201968c10158b9dc11692f712b95f..e76ba4122bb6ff887de309b3a97e8de69ca290e6 100644 (file)
@@ -70,7 +70,7 @@ void SystemInitializerCommon::Initialize() {
 #endif
 
   llvm::EnablePrettyStackTrace();
-  Log::Initialize();
+  InitializeLog();
   HostInfo::Initialize();
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
index ffdb6c4af3666cf864cbd9a3943f7765644fed84..a80b106838bc58dd6735d499877e39a5492734d1 100644 (file)
@@ -32,7 +32,6 @@
 #include <process.h> // for getpid
 #else
 #include <unistd.h>
-#include <pthread.h>
 #endif
 
 using namespace lldb_private;
@@ -182,13 +181,6 @@ void Log::Warning(const char *format, ...) {
   Printf("warning: %s", Content.c_str());
 }
 
-void Log::Initialize() {
-#ifdef LLVM_ON_UNIX
-  pthread_atfork(&Log::LockAllChannels, &Log::UnlockAllChannels, &Log::UnlockAllChannels);
-#endif
-  InitializeLldbChannel();
-}
-
 void Log::Register(llvm::StringRef name, Channel &channel) {
   auto iter = g_channel_map->try_emplace(name, channel);
   assert(iter.second == true);
@@ -329,13 +321,3 @@ void Log::Format(llvm::StringRef file, llvm::StringRef function,
   message << payload << "\n";
   WriteMessage(message.str());
 }
-
-void Log::LockAllChannels() {
-  for (auto &c: *g_channel_map)
-    c.second.m_mutex.lock();
-}
-
-void Log::UnlockAllChannels() {
-  for (auto &c: *g_channel_map)
-    c.second.m_mutex.unlock();
-}
index c9a6ef1bd1eae7771a9e73a4ceec94a371528169..0bd6d6692e37d8a2091d9d9c8d668a13a9f097bc 100644 (file)
@@ -51,7 +51,7 @@ static constexpr Log::Category g_categories[] = {
 
 static Log::Channel g_log_channel(g_categories, LIBLLDB_LOG_DEFAULT);
 
-void lldb_private::InitializeLldbChannel() {
+void lldb_private::InitializeLog() {
   Log::Register("lldb", g_log_channel);
 }