[Lldb-commits] [PATCH] D17710: Simplify GetGlobalProperties functions of Thread/Process/Target

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 29 03:38:16 PST 2016


labath created this revision.
labath added reviewers: clayborg, zturner.
labath added a subscriber: lldb-commits.

"Initialization of function-local statics is guaranteed to occur only once even when called from
multiple threads, and may be more efficient than the equivalent code using std::call_once."
<http://en.cppreference.com/w/cpp/thread/call_once>

I'd add that it's also more readable.

http://reviews.llvm.org/D17710

Files:
  source/Target/Process.cpp
  source/Target/Target.cpp
  source/Target/Thread.cpp

Index: source/Target/Thread.cpp
===================================================================
--- source/Target/Thread.cpp
+++ source/Target/Thread.cpp
@@ -61,11 +61,7 @@
 {
     // NOTE: intentional leak so we don't crash if global destructor chain gets
     // called as other threads still use the result of this function
-    static ThreadPropertiesSP *g_settings_sp_ptr = nullptr;
-    static std::once_flag g_once_flag;
-    std::call_once(g_once_flag,  []() {
-        g_settings_sp_ptr = new ThreadPropertiesSP(new ThreadProperties (true));
-    });
+    static ThreadPropertiesSP *g_settings_sp_ptr = new ThreadPropertiesSP(new ThreadProperties (true));
     return *g_settings_sp_ptr;
 }
 
Index: source/Target/Target.cpp
===================================================================
--- source/Target/Target.cpp
+++ source/Target/Target.cpp
@@ -2780,11 +2780,7 @@
 {
     // NOTE: intentional leak so we don't crash if global destructor chain gets
     // called as other threads still use the result of this function
-    static TargetPropertiesSP *g_settings_sp_ptr = nullptr;
-    static std::once_flag g_once_flag;
-    std::call_once(g_once_flag,  []() {
-        g_settings_sp_ptr = new TargetPropertiesSP(new TargetProperties(nullptr));
-    });
+    static TargetPropertiesSP *g_settings_sp_ptr = new TargetPropertiesSP(new TargetProperties(nullptr));
     return *g_settings_sp_ptr;
 }
 
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -835,11 +835,7 @@
 {
     // NOTE: intentional leak so we don't crash if global destructor chain gets
     // called as other threads still use the result of this function
-    static ProcessPropertiesSP *g_settings_sp_ptr = nullptr;
-    static std::once_flag g_once_flag;
-    std::call_once(g_once_flag,  []() {
-        g_settings_sp_ptr = new ProcessPropertiesSP(new ProcessProperties (NULL));
-    });
+    static ProcessPropertiesSP *g_settings_sp_ptr = new ProcessPropertiesSP(new ProcessProperties (NULL));
     return *g_settings_sp_ptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17710.49356.patch
Type: text/x-patch
Size: 2137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160229/868748bb/attachment-0001.bin>


More information about the lldb-commits mailing list