1 //===-- ThreadSafeDenseSet.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_ThreadSafeDenseSet_h_
12 #define liblldb_ThreadSafeDenseSet_h_
18 // Other libraries and framework includes
19 #include "llvm/ADT/DenseSet.h"
23 namespace lldb_private {
25 template <typename _ElementType, typename _MutexType = std::mutex>
26 class ThreadSafeDenseSet {
28 typedef llvm::DenseSet<_ElementType> LLVMSetType;
30 ThreadSafeDenseSet(unsigned set_initial_capacity = 0)
31 : m_set(set_initial_capacity), m_mutex() {}
33 void Insert(_ElementType e) {
34 std::lock_guard<_MutexType> guard(m_mutex);
38 void Erase(_ElementType e) {
39 std::lock_guard<_MutexType> guard(m_mutex);
43 bool Lookup(_ElementType e) {
44 std::lock_guard<_MutexType> guard(m_mutex);
45 return (m_set.count(e) > 0);
49 std::lock_guard<_MutexType> guard(m_mutex);
58 } // namespace lldb_private
60 #endif // liblldb_ThreadSafeDenseSet_h_