1 //===-- ThreadSafeDenseMap.h ------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_ThreadSafeDenseMap_h_
12 #define liblldb_ThreadSafeDenseMap_h_
18 // Other libraries and framework includes
19 #include "llvm/ADT/DenseMap.h"
23 namespace lldb_private {
25 template <typename _KeyType, typename _ValueType,
26 typename _MutexType = std::mutex>
27 class ThreadSafeDenseMap {
29 typedef llvm::DenseMap<_KeyType, _ValueType> LLVMMapType;
31 ThreadSafeDenseMap(unsigned map_initial_capacity = 0)
32 : m_map(map_initial_capacity), m_mutex() {}
34 void Insert(_KeyType k, _ValueType v) {
35 std::lock_guard<_MutexType> guard(m_mutex);
36 m_map.insert(std::make_pair(k, v));
39 void Erase(_KeyType k) {
40 std::lock_guard<_MutexType> guard(m_mutex);
44 _ValueType Lookup(_KeyType k) {
45 std::lock_guard<_MutexType> guard(m_mutex);
46 return m_map.lookup(k);
49 bool Lookup(_KeyType k, _ValueType &v) {
50 std::lock_guard<_MutexType> guard(m_mutex);
51 auto iter = m_map.find(k), end = m_map.end();
59 std::lock_guard<_MutexType> guard(m_mutex);
68 } // namespace lldb_private
70 #endif // liblldb_ThreadSafeSTLMap_h_