1 //===-- ThreadSafeDenseSet.h ------------------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadSafeDenseSet_h_
11 #define liblldb_ThreadSafeDenseSet_h_
15 #include "llvm/ADT/DenseSet.h"
18 namespace lldb_private {
20 template <typename _ElementType, typename _MutexType = std::mutex>
21 class ThreadSafeDenseSet {
23 typedef llvm::DenseSet<_ElementType> LLVMSetType;
25 ThreadSafeDenseSet(unsigned set_initial_capacity = 0)
26 : m_set(set_initial_capacity), m_mutex() {}
28 void Insert(_ElementType e) {
29 std::lock_guard<_MutexType> guard(m_mutex);
33 void Erase(_ElementType e) {
34 std::lock_guard<_MutexType> guard(m_mutex);
38 bool Lookup(_ElementType e) {
39 std::lock_guard<_MutexType> guard(m_mutex);
40 return (m_set.count(e) > 0);
44 std::lock_guard<_MutexType> guard(m_mutex);
53 } // namespace lldb_private
55 #endif // liblldb_ThreadSafeDenseSet_h_