aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Core/ThreadSafeDenseMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Core/ThreadSafeDenseMap.h')
-rw-r--r--include/lldb/Core/ThreadSafeDenseMap.h97
1 files changed, 41 insertions, 56 deletions
diff --git a/include/lldb/Core/ThreadSafeDenseMap.h b/include/lldb/Core/ThreadSafeDenseMap.h
index 6b2b59b7617c..9b52e0355314 100644
--- a/include/lldb/Core/ThreadSafeDenseMap.h
+++ b/include/lldb/Core/ThreadSafeDenseMap.h
@@ -1,4 +1,5 @@
-//===-- ThreadSafeDenseMap.h ------------------------------------------*- C++ -*-===//
+//===-- ThreadSafeDenseMap.h ------------------------------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,74 +13,58 @@
// C Includes
// C++ Includes
+#include <mutex>
// Other libraries and framework includes
#include "llvm/ADT/DenseMap.h"
// Project includes
-#include "lldb/Host/Mutex.h"
namespace lldb_private {
-
-template <typename _KeyType, typename _ValueType>
-class ThreadSafeDenseMap
-{
+
+template <typename _KeyType, typename _ValueType,
+ typename _MutexType = std::mutex>
+class ThreadSafeDenseMap {
public:
- typedef llvm::DenseMap<_KeyType,_ValueType> LLVMMapType;
-
- ThreadSafeDenseMap(unsigned map_initial_capacity = 0,
- Mutex::Type mutex_type = Mutex::eMutexTypeNormal) :
- m_map(map_initial_capacity),
- m_mutex(mutex_type)
- {
- }
-
- void
- Insert (_KeyType k, _ValueType v)
- {
- Mutex::Locker locker(m_mutex);
- m_map.insert(std::make_pair(k,v));
- }
-
- void
- Erase (_KeyType k)
- {
- Mutex::Locker locker(m_mutex);
- m_map.erase(k);
- }
-
- _ValueType
- Lookup (_KeyType k)
- {
- Mutex::Locker locker(m_mutex);
- return m_map.lookup(k);
- }
+ typedef llvm::DenseMap<_KeyType, _ValueType> LLVMMapType;
+
+ ThreadSafeDenseMap(unsigned map_initial_capacity = 0)
+ : m_map(map_initial_capacity), m_mutex() {}
+
+ void Insert(_KeyType k, _ValueType v) {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ m_map.insert(std::make_pair(k, v));
+ }
+
+ void Erase(_KeyType k) {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ m_map.erase(k);
+ }
+
+ _ValueType Lookup(_KeyType k) {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ return m_map.lookup(k);
+ }
- bool
- Lookup (_KeyType k,
- _ValueType& v)
- {
- Mutex::Locker locker(m_mutex);
- auto iter = m_map.find(k),
- end = m_map.end();
- if (iter == end)
- return false;
- v = iter->second;
- return true;
- }
+ bool Lookup(_KeyType k, _ValueType &v) {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ auto iter = m_map.find(k), end = m_map.end();
+ if (iter == end)
+ return false;
+ v = iter->second;
+ return true;
+ }
- void
- Clear ()
- {
- Mutex::Locker locker(m_mutex);
- m_map.clear();
- }
+ void Clear() {
+ std::lock_guard<_MutexType> guard(m_mutex);
+ m_map.clear();
+ }
protected:
- LLVMMapType m_map;
- Mutex m_mutex;
+ LLVMMapType m_map;
+ _MutexType m_mutex;
};
} // namespace lldb_private
-#endif // liblldb_ThreadSafeSTLMap_h_
+#endif // liblldb_ThreadSafeSTLMap_h_