Author: gclayton Date: Fri Feb 26 13:38:18 2016 New Revision: 262053 URL: http://llvm.org/viewvc/llvm-project?rev=262053&view=rev Log: Make sure the Target, Process and Thread GetGlobalProperties() static methods are thread safe.
<rdar://problem/22595283> Modified: lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/source/Target/Thread.cpp Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=262053&r1=262052&r2=262053&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Fri Feb 26 13:38:18 2016 @@ -9,6 +9,7 @@ // C Includes // C++ Includes +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/Target/Process.h" @@ -832,8 +833,11 @@ const ProcessPropertiesSP & Process::GetGlobalProperties() { static ProcessPropertiesSP g_settings_sp; - if (!g_settings_sp) - g_settings_sp.reset (new ProcessProperties (NULL)); + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { + if (!g_settings_sp) + g_settings_sp.reset (new ProcessProperties (NULL)); + }); return g_settings_sp; } Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=262053&r1=262052&r2=262053&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Fri Feb 26 13:38:18 2016 @@ -9,6 +9,7 @@ // C Includes // C++ Includes +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/Target/Target.h" @@ -2778,10 +2779,11 @@ const TargetPropertiesSP & Target::GetGlobalProperties() { static TargetPropertiesSP g_settings_sp; - if (!g_settings_sp) - { - g_settings_sp.reset(new TargetProperties(nullptr)); - } + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { + if (!g_settings_sp) + g_settings_sp.reset(new TargetProperties(nullptr)); + }); return g_settings_sp; } Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=262053&r1=262052&r2=262053&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Fri Feb 26 13:38:18 2016 @@ -9,6 +9,7 @@ // C Includes // C++ Includes +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" @@ -59,8 +60,11 @@ const ThreadPropertiesSP & Thread::GetGlobalProperties() { static ThreadPropertiesSP g_settings_sp; - if (!g_settings_sp) - g_settings_sp.reset (new ThreadProperties (true)); + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { + if (!g_settings_sp) + g_settings_sp.reset (new ThreadProperties (true)); + }); return g_settings_sp; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits