summaryrefslogtreecommitdiffstats
path: root/source/Core/ConstString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Core/ConstString.cpp')
-rw-r--r--source/Core/ConstString.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/source/Core/ConstString.cpp b/source/Core/ConstString.cpp
index 5657b48..37d24e0 100644
--- a/source/Core/ConstString.cpp
+++ b/source/Core/ConstString.cpp
@@ -11,6 +11,8 @@
#include "lldb/Host/Mutex.h"
#include "llvm/ADT/StringMap.h"
+#include <mutex>
+
using namespace lldb_private;
@@ -93,7 +95,7 @@ public:
{
Mutex::Locker locker (m_mutex);
llvm::StringRef string_ref (cstr, cstr_len);
- StringPoolEntryType& entry = m_string_map.GetOrCreateValue (string_ref, (StringPoolValueType)NULL);
+ StringPoolEntryType& entry = *m_string_map.insert (std::make_pair (string_ref, (StringPoolValueType)NULL)).first;
return entry.getKeyData();
}
return NULL;
@@ -105,7 +107,7 @@ public:
if (string_ref.data())
{
Mutex::Locker locker (m_mutex);
- StringPoolEntryType& entry = m_string_map.GetOrCreateValue (string_ref, (StringPoolValueType)NULL);
+ StringPoolEntryType& entry = *m_string_map.insert (std::make_pair (string_ref, (StringPoolValueType)NULL)).first;
return entry.getKeyData();
}
return NULL;
@@ -118,7 +120,7 @@ public:
{
Mutex::Locker locker (m_mutex);
// Make string pool entry with the mangled counterpart already set
- StringPoolEntryType& entry = m_string_map.GetOrCreateValue (llvm::StringRef (demangled_cstr), mangled_ccstr);
+ StringPoolEntryType& entry = *m_string_map.insert (std::make_pair (llvm::StringRef (demangled_cstr), mangled_ccstr)).first;
// Extract the const version of the demangled_cstr
const char *demangled_ccstr = entry.getKeyData();
@@ -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;
}
OpenPOWER on IntegriCloud