Index: include/lldb/Core/Timer.h =================================================================== --- include/lldb/Core/Timer.h +++ include/lldb/Core/Timer.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "lldb/lldb-private.h" #include "lldb/Host/TimeValue.h" @@ -84,9 +85,14 @@ TimeValue m_timer_start; uint64_t m_total_ticks; // Total running time for this timer including when other timers below this are running uint64_t m_timer_ticks; // Ticks for this timer that do not include when other timers below this one are running - static uint32_t g_depth; - static uint32_t g_display_depth; - static FILE * g_file; + + static thread_local unsigned g_depth; + + static std::atomic_bool g_quiet; + static std::atomic_uint g_display_depth; + static std::mutex g_file_mutex; + static FILE* g_file; + private: Timer(); DISALLOW_COPY_AND_ASSIGN (Timer); Index: source/Core/Timer.cpp =================================================================== --- source/Core/Timer.cpp +++ source/Core/Timer.cpp @@ -21,12 +21,16 @@ using namespace lldb_private; #define TIMER_INDENT_AMOUNT 2 -static bool g_quiet = true; -uint32_t Timer::g_depth = 0; -uint32_t Timer::g_display_depth = 0; -FILE * Timer::g_file = NULL; typedef std::vector TimerStack; typedef std::map TimerCategoryMap; + +thread_local unsigned Timer::g_depth(0); + +std::atomic_bool Timer::g_quiet(true); +std::atomic_uint Timer::g_display_depth(0); +std::mutex Timer::g_file_mutex; +FILE* Timer::g_file = nullptr; + static lldb::thread_key_t g_key; static Mutex & @@ -86,6 +90,8 @@ { if (g_quiet == false) { + std::lock_guard lock(g_file_mutex); + // Indent ::fprintf (g_file, "%*s", g_depth * TIMER_INDENT_AMOUNT, ""); // Print formatted string @@ -143,7 +149,7 @@ if (g_quiet == false) { - + std::lock_guard lock(g_file_mutex); ::fprintf (g_file, "%*s%.9f sec (%.9f sec)\n", (g_depth - 1) *TIMER_INDENT_AMOUNT, "",