[Lldb-commits] [lldb] r224310 - Instead of rolling our own, use the C++11 sanctioned solution

Enrico Granata egranata at apple.com
Mon Dec 15 18:34:13 PST 2014


Author: enrico
Date: Mon Dec 15 20:34:13 2014
New Revision: 224310

URL: http://llvm.org/viewvc/llvm-project?rev=224310&view=rev
Log:
Instead of rolling our own, use the C++11 sanctioned solution

Modified:
    lldb/trunk/source/Core/ConstString.cpp

Modified: lldb/trunk/source/Core/ConstString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConstString.cpp?rev=224310&r1=224309&r2=224310&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConstString.cpp (original)
+++ lldb/trunk/source/Core/ConstString.cpp Mon Dec 15 20:34:13 2014
@@ -11,6 +11,8 @@
 #include "lldb/Host/Mutex.h"
 #include "llvm/ADT/StringMap.h"
 
+#import <mutex>
+
 using namespace lldb_private;
 
 
@@ -184,25 +186,16 @@ protected:
 // we can't guarantee that some objects won't get destroyed after the
 // global destructor chain is run, and trying to make sure no destructors
 // touch ConstStrings is difficult.  So we leak the pool instead.
-//
-// FIXME: If we are going to keep it this way we should come up with some
-// abstraction to "pthread_once" so we don't have to check the pointer
-// every time.
 //----------------------------------------------------------------------
 static Pool &
 StringPool()
 {
-    static Mutex g_pool_initialization_mutex;
+    static std::once_flag g_pool_initialization_flag;
     static Pool *g_string_pool = NULL;
 
-    if (g_string_pool == NULL)
-    {
-        Mutex::Locker initialization_locker(g_pool_initialization_mutex);
-        if (g_string_pool == NULL)
-        {
-            g_string_pool = new Pool();
-        }
-    }
+    std::call_once(g_pool_initialization_flag, [] () {
+        g_string_pool = new Pool();
+    });
     
     return *g_string_pool;
 }





More information about the lldb-commits mailing list