[Lldb-commits] [lldb] r233999 - [Plugin/Process] Use std::call_once() to initialize.

Davide Italiano davide at freebsd.org
Thu Apr 2 21:24:32 PDT 2015


Author: davide
Date: Thu Apr  2 23:24:32 2015
New Revision: 233999

URL: http://llvm.org/viewvc/llvm-project?rev=233999&view=rev
Log:
[Plugin/Process] Use std::call_once() to initialize.

This replaces the home-grown initialization mechanism used before.

Differential Revision:  http://reviews.llvm.org/D8760	

Modified:
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
    lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
    lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
    lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp Thu Apr  2 23:24:32 2015
@@ -56,16 +56,14 @@ ProcessFreeBSD::CreateInstance(Target& t
 void
 ProcessFreeBSD::Initialize()
 {
-    static bool g_initialized = false;
+    static std::once_flag g_once_flag;
 
-    if (!g_initialized)
-    {
+    std::call_once(g_once_flag, []() {
         PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                       GetPluginDescriptionStatic(),
                                       CreateInstance);
         ProcessPOSIXLog::Initialize(GetPluginNameStatic());
-        g_initialized = true;
-    }
+    });
 }
 
 lldb_private::ConstString

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Thu Apr  2 23:24:32 2015
@@ -53,16 +53,14 @@ ProcessLinux::CreateInstance(Target &tar
 void
 ProcessLinux::Initialize()
 {
-    static bool g_initialized = false;
+    static std::once_flag g_once_flag;
 
-    if (!g_initialized)
-    {
-        g_initialized = true;
+    std::call_once(g_once_flag, []() {
         PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                       GetPluginDescriptionStatic(),
                                       CreateInstance);
         ProcessPOSIXLog::Initialize(GetPluginNameStatic());
-    }
+    });
 }
 
 //------------------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Thu Apr  2 23:24:32 2015
@@ -835,24 +835,23 @@ ProcessKDP::DoSignal (int signo)
 void
 ProcessKDP::Initialize()
 {
-    static bool g_initialized = false;
-    
-    if (g_initialized == false)
+    static std::once_flag g_once_flag;
+
+    std::call_once(g_once_flag, []()
     {
-        g_initialized = true;
         PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                        GetPluginDescriptionStatic(),
                                        CreateInstance,
-                                       DebuggerInitialize);
-        
+                                       DebuggerInitialize);a
+
         Log::Callbacks log_callbacks = {
             ProcessKDPLog::DisableLog,
             ProcessKDPLog::EnableLog,
             ProcessKDPLog::ListLogCategories
         };
-        
+
         Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks);
-    }
+    });
 }
 
 void

Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Thu Apr  2 23:24:32 2015
@@ -87,11 +87,10 @@ ProcessWindows::CreateInstance(Target &t
 void
 ProcessWindows::Initialize()
 {
-    static bool g_initialized = false;
+    static std::once_flag g_once_flag;
 
-    if (!g_initialized)
+    std::call_once(g_once_flag, []()
     {
-        g_initialized = true;
         PluginManager::RegisterPlugin(GetPluginNameStatic(),
                                       GetPluginDescriptionStatic(),
                                       CreateInstance);

Modified: lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp (original)
+++ lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp Thu Apr  2 23:24:32 2015
@@ -374,13 +374,13 @@ ProcessElfCore::Clear()
 void
 ProcessElfCore::Initialize()
 {
-    static bool g_initialized = false;
+    static std::once_flag g_once_flag;
 
-    if (g_initialized == false)
+    std::call_once(g_once_flag, []()
     {
-        g_initialized = true;
-        PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance);
-    }
+        PluginManager::RegisterPlugin (GetPluginNameStatic(),
+          GetPluginDescriptionStatic(), CreateInstance);
+    });
 }
 
 lldb::addr_t

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Apr  2 23:24:32 2015
@@ -2958,16 +2958,15 @@ ProcessGDBRemote::KillDebugserverProcess
 void
 ProcessGDBRemote::Initialize()
 {
-    static bool g_initialized = false;
+    static std::once_flag g_once_flag;
 
-    if (g_initialized == false)
+    std::call_once(g_once_flag, []()
     {
-        g_initialized = true;
         PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                        GetPluginDescriptionStatic(),
                                        CreateInstance,
                                        DebuggerInitialize);
-    }
+    });
 }
 
 void

Modified: lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp?rev=233999&r1=233998&r2=233999&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp (original)
+++ lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp Thu Apr  2 23:24:32 2015
@@ -483,15 +483,13 @@ ProcessMachCore::Clear()
 void
 ProcessMachCore::Initialize()
 {
-    static bool g_initialized = false;
-    
-    if (g_initialized == false)
-    {
-        g_initialized = true;
+    static std::once_flag g_once_flag;
+
+    std::call_once(g_once_flag, []() {
         PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                        GetPluginDescriptionStatic(),
-                                       CreateInstance);        
-    }
+                                       CreateInstance);
+    });
 }
 
 addr_t





More information about the lldb-commits mailing list