krytarowski created this revision.
krytarowski added a project: LLDB.

The std::call_once implementation in libstdc++ has problems on few systems: 
NetBSD, OpenBSD and Linux PPC. LLVM ships with a homegrown implementation 
llvm::call_once to help on these platforms.

      

This change is required in the NetBSD LLDB port. std::call_once with libstdc++ 
results with crashing the debugger.


Repository:
  rL LLVM

https://reviews.llvm.org/D29288

Files:
  include/lldb/Core/Debugger.h
  source/Commands/CommandObjectPlatform.cpp
  source/Core/ConstString.cpp
  source/Core/Debugger.cpp
  source/Core/ModuleList.cpp
  source/Host/common/Editline.cpp
  source/Host/common/HostInfoBase.cpp
  source/Host/linux/HostInfoLinux.cpp
  source/Host/windows/HostInfoWindows.cpp
  source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  source/Plugins/Language/Go/GoLanguage.cpp
  source/Plugins/Language/Java/JavaLanguage.cpp
  source/Plugins/Language/ObjC/ObjCLanguage.cpp
  source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
  source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
  source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
  source/Plugins/Process/Windows/Common/ProcessWindows.cpp
  source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
  source/Plugins/Process/mach-core/ProcessMachCore.cpp
  source/Plugins/Process/minidump/ProcessMinidump.cpp
  source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
  source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Symbol/ClangASTContext.cpp
  source/Symbol/GoASTContext.cpp
  source/Target/Language.cpp
  tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp

Index: tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
===================================================================
--- tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
+++ tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
@@ -46,10 +46,10 @@
     s_os_activity_stream_set_event_handler;
 
 bool LookupSPICalls() {
-  static std::once_flag s_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(s_once_flag);
   static bool s_has_spi;
 
-  std::call_once(s_once_flag, [] {
+  llvm::call_once(s_once_flag, [] {
     dlopen ("/System/Library/PrivateFrameworks/LoggingSupport.framework/LoggingSupport", RTLD_NOW);
     s_os_activity_stream_for_pid = (os_activity_stream_for_pid_t)dlsym(
         RTLD_DEFAULT, "os_activity_stream_for_pid");
Index: source/Target/Language.cpp
===================================================================
--- source/Target/Language.cpp
+++ source/Target/Language.cpp
@@ -20,29 +20,32 @@
 #include "lldb/Symbol/TypeList.h"
 #include "lldb/Target/Target.h"
 
+#include "llvm/Support/Threading.h"
+
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
+using namespace llvm;
 
 typedef std::unique_ptr<Language> LanguageUP;
 typedef std::map<lldb::LanguageType, LanguageUP> LanguagesMap;
 
 static LanguagesMap &GetLanguagesMap() {
   static LanguagesMap *g_map = nullptr;
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
 
-  std::call_once(g_initialize, [] {
+  llvm::call_once(g_initialize, [] {
     g_map = new LanguagesMap(); // NOTE: INTENTIONAL LEAK due to global
                                 // destructor chain
   });
 
   return *g_map;
 }
 static std::mutex &GetLanguagesMutex() {
   static std::mutex *g_mutex = nullptr;
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
 
-  std::call_once(g_initialize, [] {
+  llvm::call_once(g_initialize, [] {
     g_mutex = new std::mutex(); // NOTE: INTENTIONAL LEAK due to global
                                 // destructor chain
   });
Index: source/Symbol/GoASTContext.cpp
===================================================================
--- source/Symbol/GoASTContext.cpp
+++ source/Symbol/GoASTContext.cpp
@@ -25,10 +25,13 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Target.h"
 
+#include "llvm/Support/Threading.h"
+
 #include "Plugins/ExpressionParser/Go/GoUserExpression.h"
 #include "Plugins/SymbolFile/DWARF/DWARFASTParserGo.h"
 
 using namespace lldb;
+using namespace llvm;
 
 namespace lldb_private {
 class GoArray;
@@ -593,8 +596,8 @@
   if (name) {
     typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
     static TypeNameToBasicTypeMap g_type_map;
-    static std::once_flag g_once_flag;
-    std::call_once(g_once_flag, []() {
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+    llvm::call_once(g_once_flag, []() {
       // "void"
       g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid);
       // "int"
Index: source/Symbol/ClangASTContext.cpp
===================================================================
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -127,8 +127,8 @@
 
 static ClangASTMap &GetASTMap() {
   static ClangASTMap *g_map_ptr = nullptr;
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins
   });
   return *g_map_ptr;
@@ -954,8 +954,8 @@
   if (name) {
     typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
     static TypeNameToBasicTypeMap g_type_map;
-    static std::once_flag g_once_flag;
-    std::call_once(g_once_flag, []() {
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+    llvm::call_once(g_once_flag, []() {
       // "void"
       g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid);
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -305,7 +305,6 @@
   typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
 
   struct DWARFDataSegment {
-    std::once_flag m_flag;
     lldb_private::DWARFDataExtractor m_data;
   };
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -11,6 +11,7 @@
 
 // Other libraries and framework includes
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Threading.h"
 
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Module.h"
@@ -87,6 +88,7 @@
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 // static inline bool
 // child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
@@ -553,8 +555,8 @@
 const DWARFDataExtractor &
 SymbolFileDWARF::GetCachedSectionData(lldb::SectionType sect_type,
                                       DWARFDataSegment &data_segment) {
-  std::call_once(data_segment.m_flag, &SymbolFileDWARF::LoadSectionData, this,
-                 sect_type, std::ref(data_segment.m_data));
+  LLVM_DEFINE_ONCE_FLAG(m_flag);
+  llvm::call_once(m_flag,  [this, sect_type, &data_segment]{ this->LoadSectionData(sect_type, std::ref(data_segment.m_data));});
   return data_segment.m_data;
 }
 
@@ -1630,13 +1632,13 @@
               VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
               if (var_sp && !var_sp->GetLocationIsConstantValueData()) {
                 const DWARFExpression &location = var_sp->LocationExpression();
-                Value location_result;
+                lldb_private::Value location_result;
                 Error error;
                 if (location.Evaluate(nullptr, nullptr, nullptr,
                                       LLDB_INVALID_ADDRESS, nullptr, nullptr,
                                       location_result, &error)) {
                   if (location_result.GetValueType() ==
-                      Value::eValueTypeFileAddress) {
+                      lldb_private::Value::eValueTypeFileAddress) {
                     lldb::addr_t file_addr =
                         location_result.GetScalar().ULongLong();
                     lldb::addr_t byte_size = 1;
Index: source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -51,9 +51,11 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Threading.h"
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 static ScriptInterpreterPython::SWIGInitCallback g_swig_init_callback = nullptr;
 static ScriptInterpreterPython::SWIGBreakpointCallbackFunction
@@ -338,9 +340,9 @@
 }
 
 void ScriptInterpreterPython::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(),
                                   lldb::eScriptLanguagePython, CreateInstance);
Index: source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
===================================================================
--- source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
+++ source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
@@ -15,10 +15,13 @@
 #include "lldb/Core/StringList.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 
+#include "llvm/Support/Threading.h"
+
 #include <mutex>
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 ScriptInterpreterNone::ScriptInterpreterNone(CommandInterpreter &interpreter)
     : ScriptInterpreter(interpreter, eScriptLanguageNone) {}
@@ -39,9 +42,9 @@
 }
 
 void ScriptInterpreterNone::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(),
                                   lldb::eScriptLanguageNone, CreateInstance);
Index: source/Plugins/Process/minidump/ProcessMinidump.cpp
===================================================================
--- source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -25,11 +25,14 @@
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/LLDBAssert.h"
 
+#include "llvm/Support/Threading.h"
+
 // C includes
 // C++ includes
 
 using namespace lldb_private;
 using namespace minidump;
+using namespace llvm;
 
 ConstString ProcessMinidump::GetPluginNameStatic() {
   static ConstString g_name("minidump");
@@ -92,9 +95,9 @@
 }
 
 void ProcessMinidump::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(),
                                   ProcessMinidump::CreateInstance);
Index: source/Plugins/Process/mach-core/ProcessMachCore.cpp
===================================================================
--- source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -39,12 +39,15 @@
 // Needed for the plug-in names for the dynamic loaders.
 #include "lldb/Utility/SafeMachO.h"
 
+#include "llvm/Support/Threading.h"
+
 #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
 #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 ConstString ProcessMachCore::GetPluginNameStatic() {
   static ConstString g_name("mach-o-core");
@@ -579,9 +582,9 @@
 void ProcessMachCore::Clear() { m_thread_list.Clear(); }
 
 void ProcessMachCore::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance);
   });
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -14,11 +14,14 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Interpreter/Args.h"
 
+#include "llvm/Support/Threading.h"
+
 #include "ProcessGDBRemote.h"
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace llvm;
 
 // We want to avoid global constructors where code needs to be run so here we
 // control access to our static g_log_sp by hiding it in a singleton function
@@ -34,9 +37,9 @@
 
 void ProcessGDBRemoteLog::Initialize() {
   static ConstString g_name("gdb-remote");
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
 
     Log::RegisterLogChannel(g_name, log_callbacks);
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -81,11 +81,13 @@
 
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Threading.h"
 
 #define DEBUGSERVER_BASENAME "debugserver"
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace llvm;
 
 namespace lldb {
 // Provide a function that can easily dump the packet history if we know a
@@ -3434,9 +3436,9 @@
 }
 
 void ProcessGDBRemote::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance,
                                   DebuggerInitialize);
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -36,13 +36,16 @@
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/JSON.h"
 
+#include "llvm/Support/Threading.h"
+
 // Project includes
 #include "Utility/StringExtractorGDBRemote.h"
 #include "Utility/UriParser.h"
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace llvm;
 
 //----------------------------------------------------------------------
 // GDBRemoteCommunicationServerPlatform constructor
@@ -528,9 +531,9 @@
 
 const FileSpec &GDBRemoteCommunicationServerPlatform::GetDomainSocketDir() {
   static FileSpec g_domainsocket_dir;
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     const char *domainsocket_dir_env =
         ::getenv("LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
     if (domainsocket_dir_env != nullptr)
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===================================================================
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -27,6 +27,7 @@
 #include "lldb/Target/UnixSignals.h"
 
 #include "llvm/Support/ELF.h"
+#include "llvm/Support/Threading.h"
 
 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
@@ -36,6 +37,7 @@
 #include "ThreadElfCore.h"
 
 using namespace lldb_private;
+using namespace llvm;
 
 ConstString ProcessElfCore::GetPluginNameStatic() {
   static ConstString g_name("elf-core");
@@ -398,9 +400,9 @@
 }
 
 void ProcessElfCore::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance);
   });
Index: source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
+++ source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
@@ -17,20 +17,21 @@
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 // We want to avoid global constructors where code needs to be run so here we
 // control access to our static g_log_sp by hiding it in a singleton function
 // that will construct the static g_log_sp the first time this function is
 // called.
 static bool g_log_enabled = false;
 static Log *g_log = nullptr;
 
-static llvm::ManagedStatic<std::once_flag> g_once_flag;
+LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
 void ProcessWindowsLog::Initialize() {
   static ConstString g_name("windows");
 
-  std::call_once(*g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
 
     Log::RegisterLogChannel(g_name, log_callbacks);
Index: source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -41,6 +41,7 @@
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 std::string GetProcessExecutableName(HANDLE process_handle) {
@@ -102,9 +103,9 @@
 }
 
 void ProcessWindows::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance);
   });
Index: source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
+++ source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
@@ -15,10 +15,13 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Interpreter/Args.h"
 
+#include "llvm/Support/Threading.h"
+
 #include "ProcessPOSIXLog.h"
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 // We want to avoid global constructors where code needs to be run so here we
 // control access to our static g_log_sp by hiding it in a singleton function
@@ -33,9 +36,9 @@
 }
 
 void ProcessPOSIXLog::Initialize(ConstString name) {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, [name]() {
+  llvm::call_once(g_once_flag, [name]() {
     Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
 
     Log::RegisterLogChannel(name, log_callbacks);
Index: source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
===================================================================
--- source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -50,6 +50,7 @@
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 
@@ -718,9 +719,9 @@
 }
 
 void ProcessKDP::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance,
                                   DebuggerInitialize);
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -75,9 +75,9 @@
 
 static bool ProcessVmReadvSupported() {
   static bool is_supported;
-  static std::once_flag flag;
+  LLVM_DEFINE_ONCE_FLAG(flag);
 
-  std::call_once(flag, [] {
+  llvm::call_once(flag, [] {
     Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
     uint32_t source = 0x47424742;
Index: source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
===================================================================
--- source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
+++ source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
@@ -48,6 +48,7 @@
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 UnixSignalsSP &GetFreeBSDSignals() {
@@ -71,9 +72,9 @@
 }
 
 void ProcessFreeBSD::Initialize() {
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                   GetPluginDescriptionStatic(), CreateInstance);
     ProcessPOSIXLog::Initialize(GetPluginNameStatic());
Index: source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===================================================================
--- source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -40,13 +40,15 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Threading.h"
 
 #if defined(__APPLE__)
 #include <TargetConditionals.h> // for TARGET_OS_TV, TARGET_OS_WATCH
 #endif
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 //------------------------------------------------------------------
 /// Default Constructor
@@ -1452,8 +1454,8 @@
 
 static FileSpec GetXcodeContentsPath() {
   static FileSpec g_xcode_filespec;
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
 
     FileSpec fspec;
 
@@ -1835,8 +1837,8 @@
 
   // Find the global list of directories that we will search for
   // executables once so we don't keep doing the work over and over.
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
 
     // When locating executables, trust the DEVELOPER_DIR first if it is set
     FileSpec xcode_contents_dir = GetXcodeContentsPath();
Index: source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
===================================================================
--- source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
+++ source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
@@ -242,8 +242,8 @@
 
 void PlatformAppleSimulator::LoadCoreSimulator() {
 #if defined(__APPLE__)
-  static std::once_flag g_load_core_sim_flag;
-  std::call_once(g_load_core_sim_flag, [this] {
+  LLVM_DEFINE_ONCE_FLAG(g_load_core_sim_flag);
+  llvm::call_once(g_load_core_sim_flag, [this] {
     const std::string core_sim_path(GetCoreSimulatorPath().GetPath());
     if (core_sim_path.size())
       dlopen(core_sim_path.c_str(), RTLD_LAZY);
Index: source/Plugins/Language/ObjC/ObjCLanguage.cpp
===================================================================
--- source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -36,6 +36,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
+using namespace llvm;
 
 void ObjCLanguage::Initialize() {
   PluginManager::RegisterPlugin(GetPluginNameStatic(), "Objective-C Language",
@@ -857,10 +858,10 @@
 }
 
 lldb::TypeCategoryImplSP ObjCLanguage::GetFormatters() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static TypeCategoryImplSP g_category;
 
-  std::call_once(g_initialize, [this]() -> void {
+  llvm::call_once(g_initialize, [this]() -> void {
     DataVisualization::Categories::GetCategory(GetPluginName(), g_category);
     if (g_category) {
       LoadCoreMediaFormatters(g_category);
Index: source/Plugins/Language/Java/JavaLanguage.cpp
===================================================================
--- source/Plugins/Language/Java/JavaLanguage.cpp
+++ source/Plugins/Language/Java/JavaLanguage.cpp
@@ -15,6 +15,7 @@
 
 // Other libraries and framework includes
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Threading.h"
 
 // Project includes
 #include "JavaFormatterFunctions.h"
@@ -28,6 +29,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
+using namespace llvm;
 
 void JavaLanguage::Initialize() {
   PluginManager::RegisterPlugin(GetPluginNameStatic(), "Java Language",
@@ -64,10 +66,10 @@
 }
 
 lldb::TypeCategoryImplSP JavaLanguage::GetFormatters() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static TypeCategoryImplSP g_category;
 
-  std::call_once(g_initialize, [this]() -> void {
+  llvm::call_once(g_initialize, [this]() -> void {
     DataVisualization::Categories::GetCategory(GetPluginName(), g_category);
     if (g_category) {
       llvm::StringRef array_regexp("^.*\\[\\]&?$");
Index: source/Plugins/Language/Go/GoLanguage.cpp
===================================================================
--- source/Plugins/Language/Go/GoLanguage.cpp
+++ source/Plugins/Language/Go/GoLanguage.cpp
@@ -27,6 +27,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
+using namespace llvm;
 
 void GoLanguage::Initialize() {
   PluginManager::RegisterPlugin(GetPluginNameStatic(), "Go Language",
@@ -62,10 +63,10 @@
 
 HardcodedFormatters::HardcodedSummaryFinder
 GoLanguage::GetHardcodedSummaries() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static HardcodedFormatters::HardcodedSummaryFinder g_formatters;
 
-  std::call_once(g_initialize, []() -> void {
+  llvm::call_once(g_initialize, []() -> void {
     g_formatters.push_back(
         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
            FormatManager &) -> TypeSummaryImpl::SharedPointer {
@@ -104,10 +105,10 @@
 
 HardcodedFormatters::HardcodedSyntheticFinder
 GoLanguage::GetHardcodedSynthetics() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static HardcodedFormatters::HardcodedSyntheticFinder g_formatters;
 
-  std::call_once(g_initialize, []() -> void {
+  llvm::call_once(g_initialize, []() -> void {
     g_formatters.push_back(
         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
            FormatManager &fmt_mgr) -> SyntheticChildren::SharedPointer {
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -33,6 +33,7 @@
 #include "lldb/DataFormatters/DataVisualization.h"
 #include "lldb/DataFormatters/FormattersHelpers.h"
 #include "lldb/DataFormatters/VectorType.h"
+#include "llvm/Support/Threading.h"
 
 #include "BlockPointer.h"
 #include "CxxStringTypes.h"
@@ -43,6 +44,7 @@
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
+using namespace llvm;
 
 void CPlusPlusLanguage::Initialize() {
   PluginManager::RegisterPlugin(GetPluginNameStatic(), "C++ Language",
@@ -1036,10 +1038,10 @@
 }
 
 lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static TypeCategoryImplSP g_category;
 
-  std::call_once(g_initialize, [this]() -> void {
+  llvm::call_once(g_initialize, [this]() -> void {
     DataVisualization::Categories::GetCategory(GetPluginName(), g_category);
     if (g_category) {
       LoadLibCxxFormatters(g_category);
@@ -1052,11 +1054,11 @@
 
 HardcodedFormatters::HardcodedSummaryFinder
 CPlusPlusLanguage::GetHardcodedSummaries() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static ConstString g_vectortypes("VectorTypes");
   static HardcodedFormatters::HardcodedSummaryFinder g_formatters;
 
-  std::call_once(g_initialize, []() -> void {
+  llvm::call_once(g_initialize, []() -> void {
     g_formatters.push_back(
         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
            FormatManager &) -> TypeSummaryImpl::SharedPointer {
@@ -1116,11 +1118,11 @@
 
 HardcodedFormatters::HardcodedSyntheticFinder
 CPlusPlusLanguage::GetHardcodedSynthetics() {
-  static std::once_flag g_initialize;
+  LLVM_DEFINE_ONCE_FLAG(g_initialize);
   static ConstString g_vectortypes("VectorTypes");
   static HardcodedFormatters::HardcodedSyntheticFinder g_formatters;
 
-  std::call_once(g_initialize, []() -> void {
+  llvm::call_once(g_initialize, []() -> void {
     g_formatters.push_back([](lldb_private::ValueObject &valobj,
                               lldb::DynamicValueType,
                               FormatManager &
Index: source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -35,6 +35,7 @@
 #include "lldb/Utility/LLDBAssert.h"
 
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 // Any Clang compiler requires a consumer for diagnostics.  This one stores them
@@ -143,9 +144,9 @@
 static FileSpec GetResourceDir() {
   static FileSpec g_cached_resource_dir;
 
-  static std::once_flag g_once_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
 
-  std::call_once(g_once_flag, []() {
+  llvm::call_once(g_once_flag, []() {
     HostInfo::GetLLDBPath(lldb::ePathTypeClangDir, g_cached_resource_dir);
   });
 
Index: source/Host/windows/HostInfoWindows.cpp
===================================================================
--- source/Host/windows/HostInfoWindows.cpp
+++ source/Host/windows/HostInfoWindows.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 using namespace lldb_private;
+using namespace llvm;
 
 FileSpec HostInfoWindows::m_program_filespec;
 
@@ -90,8 +91,8 @@
 }
 
 FileSpec HostInfoWindows::GetProgramFileSpec() {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     std::vector<wchar_t> buffer(PATH_MAX);
     ::GetModuleFileNameW(NULL, buffer.data(), buffer.size());
     std::string path;
Index: source/Host/linux/HostInfoLinux.cpp
===================================================================
--- source/Host/linux/HostInfoLinux.cpp
+++ source/Host/linux/HostInfoLinux.cpp
@@ -19,6 +19,7 @@
 #include <mutex> // std::once
 
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 struct HostInfoLinuxFields {
@@ -44,8 +45,8 @@
 bool HostInfoLinux::GetOSVersion(uint32_t &major, uint32_t &minor,
                                  uint32_t &update) {
   static bool success = false;
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
 
     struct utsname un;
     if (uname(&un) == 0) {
@@ -100,8 +101,8 @@
 llvm::StringRef HostInfoLinux::GetDistributionId() {
   // Try to run 'lbs_release -i', and use that response
   // for the distribution id.
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
 
     Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST));
     if (log)
Index: source/Host/common/HostInfoBase.cpp
===================================================================
--- source/Host/common/HostInfoBase.cpp
+++ source/Host/common/HostInfoBase.cpp
@@ -22,13 +22,15 @@
 #include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/Threading.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include <mutex> // std::once
 #include <thread>
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 namespace {
 //----------------------------------------------------------------------
@@ -79,45 +81,45 @@
 }
 
 uint32_t HostInfoBase::GetNumberCPUS() {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     g_fields->m_number_cpus = std::thread::hardware_concurrency();
   });
   return g_fields->m_number_cpus;
 }
 
 uint32_t HostInfoBase::GetMaxThreadNameLength() { return 0; }
 
 llvm::StringRef HostInfoBase::GetVendorString() {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     g_fields->m_vendor_string =
         HostInfo::GetArchitecture().GetTriple().getVendorName().str();
   });
   return g_fields->m_vendor_string;
 }
 
 llvm::StringRef HostInfoBase::GetOSString() {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     g_fields->m_os_string =
         std::move(HostInfo::GetArchitecture().GetTriple().getOSName());
   });
   return g_fields->m_os_string;
 }
 
 llvm::StringRef HostInfoBase::GetTargetTriple() {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     g_fields->m_host_triple =
         HostInfo::GetArchitecture().GetTriple().getTriple();
   });
   return g_fields->m_host_triple;
 }
 
 const ArchSpec &HostInfoBase::GetArchitecture(ArchitectureKind arch_kind) {
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     HostInfo::ComputeHostArchitectureSupport(g_fields->m_host_arch_32,
                                              g_fields->m_host_arch_64);
   });
@@ -144,9 +146,9 @@
   FileSpec *result = nullptr;
   switch (type) {
   case lldb::ePathTypeLLDBShlibDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success =
           HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -158,9 +160,9 @@
       result = &g_fields->m_lldb_so_dir;
   } break;
   case lldb::ePathTypeSupportExecutableDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeSupportExeDirectory(
           g_fields->m_lldb_support_exe_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -173,9 +175,9 @@
       result = &g_fields->m_lldb_support_exe_dir;
   } break;
   case lldb::ePathTypeHeaderDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
       if (log)
@@ -186,9 +188,9 @@
       result = &g_fields->m_lldb_headers_dir;
   } break;
   case lldb::ePathTypePythonDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputePythonDirectory(g_fields->m_lldb_python_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
       if (log)
@@ -199,9 +201,9 @@
       result = &g_fields->m_lldb_python_dir;
   } break;
   case lldb::ePathTypeClangDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success =
           HostInfo::ComputeClangDirectory(g_fields->m_lldb_clang_resource_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -214,9 +216,9 @@
       result = &g_fields->m_lldb_clang_resource_dir;
   } break;
   case lldb::ePathTypeLLDBSystemPlugins: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeSystemPluginsDirectory(
           g_fields->m_lldb_system_plugin_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -229,9 +231,9 @@
       result = &g_fields->m_lldb_system_plugin_dir;
   } break;
   case lldb::ePathTypeLLDBUserPlugins: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeUserPluginsDirectory(
           g_fields->m_lldb_user_plugin_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -244,9 +246,9 @@
       result = &g_fields->m_lldb_user_plugin_dir;
   } break;
   case lldb::ePathTypeLLDBTempSystemDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeProcessTempFileDirectory(
           g_fields->m_lldb_process_tmp_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
@@ -259,9 +261,9 @@
       result = &g_fields->m_lldb_process_tmp_dir;
   } break;
   case lldb::ePathTypeGlobalLLDBTempSystemDir: {
-    static std::once_flag g_once_flag;
+    LLVM_DEFINE_ONCE_FLAG(g_once_flag);
     static bool success = false;
-    std::call_once(g_once_flag, []() {
+    llvm::call_once(g_once_flag, []() {
       success = HostInfo::ComputeGlobalTempFileDirectory(
           g_fields->m_lldb_global_tmp_dir);
       Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
Index: source/Host/common/Editline.cpp
===================================================================
--- source/Host/common/Editline.cpp
+++ source/Host/common/Editline.cpp
@@ -24,6 +24,7 @@
 
 using namespace lldb_private;
 using namespace lldb_private::line_editor;
+using namespace llvm;
 
 // Workaround for what looks like an OS X-specific issue, but other platforms
 // may benefit from something similar if issues arise.  The libedit library
@@ -1151,8 +1152,8 @@
     if (term_fd != -1) {
       static std::mutex *g_init_terminal_fds_mutex_ptr = nullptr;
       static std::set<int> *g_init_terminal_fds_ptr = nullptr;
-      static std::once_flag g_once_flag;
-      std::call_once(g_once_flag, [&]() {
+      LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+      llvm::call_once(g_once_flag, [&]() {
         g_init_terminal_fds_mutex_ptr =
             new std::mutex(); // NOTE: Leak to avoid C++ destructor chain issues
         g_init_terminal_fds_ptr = new std::set<int>(); // NOTE: Leak to avoid
Index: source/Core/ModuleList.cpp
===================================================================
--- source/Core/ModuleList.cpp
+++ source/Core/ModuleList.cpp
@@ -26,8 +26,11 @@
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/VariableList.h"
 
+#include "llvm/Support/Threading.h"
+
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 ModuleList::ModuleList()
     : m_modules(), m_modules_mutex(), m_notifier(nullptr) {}
@@ -644,8 +647,8 @@
 
 static ModuleList &GetSharedModuleList() {
   static ModuleList *g_shared_module_list = nullptr;
-  static std::once_flag g_once_flag;
-  std::call_once(g_once_flag, []() {
+  LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+  llvm::call_once(g_once_flag, []() {
     // NOTE: Intentionally leak the module list so a program doesn't have to
     // cleanup all modules and object files as it exits. This just wastes time
     // doing a bunch of cleanup that isn't required.
Index: source/Core/Debugger.cpp
===================================================================
--- source/Core/Debugger.cpp
+++ source/Core/Debugger.cpp
@@ -61,8 +61,11 @@
 #include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/lldb-private.h"
 
+#include "llvm/Support/Threading.h"
+
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 static lldb::user_id_t g_unique_id = 1;
 static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
@@ -710,7 +713,7 @@
       m_input_reader_stack(), m_instance_name(), m_loaded_plugins(),
       m_event_handler_thread(), m_io_handler_thread(),
       m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
-      m_forward_listener_sp(), m_clear_once() {
+      m_forward_listener_sp() {
   char instance_cstr[256];
   snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
   m_instance_name.SetCString(instance_cstr);
@@ -762,7 +765,8 @@
   //     static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
   //     static void Debugger::Terminate();
   //----------------------------------------------------------------------
-  std::call_once(m_clear_once, [this]() {
+  LLVM_DEFINE_ONCE_FLAG(m_clear_once);
+  llvm::call_once(m_clear_once, [this]() {
     ClearIOHandlers();
     StopIOHandlerThread();
     StopEventHandlerThread();
Index: source/Core/ConstString.cpp
===================================================================
--- source/Core/ConstString.cpp
+++ source/Core/ConstString.cpp
@@ -19,10 +19,13 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/RWMutex.h"
 
+#include "llvm/Support/Atomic.h"
+
 // Project includes
 #include "lldb/Core/Stream.h"
 
 using namespace lldb_private;
+using namespace llvm;
 
 class Pool {
 public:
@@ -191,10 +194,10 @@
 // touch ConstStrings is difficult.  So we leak the pool instead.
 //----------------------------------------------------------------------
 static Pool &StringPool() {
-  static std::once_flag g_pool_initialization_flag;
+  LLVM_DEFINE_ONCE_FLAG(g_pool_initialization_flag);
   static Pool *g_string_pool = nullptr;
 
-  std::call_once(g_pool_initialization_flag,
+  llvm::call_once(g_pool_initialization_flag,
                  []() { g_string_pool = new Pool(); });
 
   return *g_string_pool;
Index: source/Commands/CommandObjectPlatform.cpp
===================================================================
--- source/Commands/CommandObjectPlatform.cpp
+++ source/Commands/CommandObjectPlatform.cpp
@@ -30,9 +30,11 @@
 #include "lldb/Utility/Utils.h"
 
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Threading.h"
 
 using namespace lldb;
 using namespace lldb_private;
+using namespace llvm;
 
 static mode_t ParsePermissionString(const char *) = delete;
 
@@ -1249,8 +1251,8 @@
   public:
     CommandOptions()
         : Options(), match_info(), show_args(false), verbose(false) {
-      static std::once_flag g_once_flag;
-      std::call_once(g_once_flag, []() {
+      LLVM_DEFINE_ONCE_FLAG(g_once_flag);
+      llvm::call_once(g_once_flag, []() {
         PosixPlatformCommandOptionValidator *posix_validator =
             new PosixPlatformCommandOptionValidator();
         for (auto &Option : g_platform_process_list_options) {
Index: include/lldb/Core/Debugger.h
===================================================================
--- include/lldb/Core/Debugger.h
+++ include/lldb/Core/Debugger.h
@@ -374,7 +374,6 @@
   HostThread m_io_handler_thread;
   Broadcaster m_sync_broadcaster;
   lldb::ListenerSP m_forward_listener_sp;
-  std::once_flag m_clear_once;
 
   //----------------------------------------------------------------------
   // Events for m_sync_broadcaster
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to