LLDB  mainline
ThreadSafeDenseSet.h
Go to the documentation of this file.
1 //===-- ThreadSafeDenseSet.h ------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ThreadSafeDenseSet_h_
11 #define liblldb_ThreadSafeDenseSet_h_
12 
13 #include <mutex>
14 
15 #include "llvm/ADT/DenseSet.h"
16 
17 
18 namespace lldb_private {
19 
20 template <typename _ElementType, typename _MutexType = std::mutex>
22 public:
23  typedef llvm::DenseSet<_ElementType> LLVMSetType;
24 
25  ThreadSafeDenseSet(unsigned set_initial_capacity = 0)
26  : m_set(set_initial_capacity), m_mutex() {}
27 
28  void Insert(_ElementType e) {
29  std::lock_guard<_MutexType> guard(m_mutex);
30  m_set.insert(e);
31  }
32 
33  void Erase(_ElementType e) {
34  std::lock_guard<_MutexType> guard(m_mutex);
35  m_set.erase(e);
36  }
37 
38  bool Lookup(_ElementType e) {
39  std::lock_guard<_MutexType> guard(m_mutex);
40  return (m_set.count(e) > 0);
41  }
42 
43  void Clear() {
44  std::lock_guard<_MutexType> guard(m_mutex);
45  m_set.clear();
46  }
47 
48 protected:
50  _MutexType m_mutex;
51 };
52 
53 } // namespace lldb_private
54 
55 #endif // liblldb_ThreadSafeDenseSet_h_
lldb_private::ThreadSafeDenseSet::m_set
LLVMSetType m_set
Definition: ThreadSafeDenseSet.h:49
lldb_private::ThreadSafeDenseSet::LLVMSetType
llvm::DenseSet< _ElementType > LLVMSetType
Definition: ThreadSafeDenseSet.h:23
lldb_private::ThreadSafeDenseSet
Definition: ThreadSafeDenseSet.h:21
lldb_private::ThreadSafeDenseSet::m_mutex
_MutexType m_mutex
Definition: ThreadSafeDenseSet.h:50
lldb_private::ThreadSafeDenseSet::Insert
void Insert(_ElementType e)
Definition: ThreadSafeDenseSet.h:28
lldb_private::ThreadSafeDenseSet::Clear
void Clear()
Definition: ThreadSafeDenseSet.h:43
lldb_private::ThreadSafeDenseSet::ThreadSafeDenseSet
ThreadSafeDenseSet(unsigned set_initial_capacity=0)
Definition: ThreadSafeDenseSet.h:25
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ThreadSafeDenseSet::Erase
void Erase(_ElementType e)
Definition: ThreadSafeDenseSet.h:33
lldb_private::ThreadSafeDenseSet::Lookup
bool Lookup(_ElementType e)
Definition: ThreadSafeDenseSet.h:38