From: Greg Clayton Date: Thu, 24 Mar 2016 21:46:47 +0000 (+0000) Subject: Get rid of a global constructor that was causing a warning on MacOSX and make the... X-Git-Tag: llvmorg-3.9.0-rc1~10979 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e1232af42901b33ce9c54987cd9d86f1bdfb1b9;p=platform%2Fupstream%2Fllvm.git Get rid of a global constructor that was causing a warning on MacOSX and make the Timer safe to use after the main threads global destructor chain is called. llvm-svn: 264346 --- diff --git a/lldb/include/lldb/Core/Timer.h b/lldb/include/lldb/Core/Timer.h index 4996db6..4d89700 100644 --- a/lldb/include/lldb/Core/Timer.h +++ b/lldb/include/lldb/Core/Timer.h @@ -86,7 +86,6 @@ protected: static std::atomic g_quiet; static std::atomic g_display_depth; - static std::mutex g_file_mutex; private: Timer(); diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp index 7a6e5de..7317598 100644 --- a/lldb/source/Core/Timer.cpp +++ b/lldb/source/Core/Timer.cpp @@ -39,7 +39,18 @@ namespace std::atomic Timer::g_quiet(true); std::atomic Timer::g_display_depth(0); -std::mutex Timer::g_file_mutex; +static std::mutex & +GetFileMutex() +{ + static std::mutex *g_file_mutex_ptr = nullptr; + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { + // leaked on purpose to ensure this mutex works after main thread has run + // global C++ destructor chain + g_file_mutex_ptr = new std::mutex(); + }); + return *g_file_mutex_ptr; +} static Mutex & @@ -97,7 +108,7 @@ Timer::Timer (const char *category, const char *format, ...) : { if (g_quiet == false) { - std::lock_guard lock(g_file_mutex); + std::lock_guard lock(GetFileMutex()); // Indent ::fprintf(stdout, "%*s", stack->m_depth * TIMER_INDENT_AMOUNT, ""); @@ -152,7 +163,7 @@ Timer::~Timer() if (g_quiet == false) { - std::lock_guard lock(g_file_mutex); + std::lock_guard lock(GetFileMutex()); ::fprintf(stdout, "%*s%.9f sec (%.9f sec)\n", (stack->m_depth - 1) * TIMER_INDENT_AMOUNT, "", total_nsec / 1000000000.0, timer_nsec / 1000000000.0); }