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
18namespace lldb_private {
19
20template <typename _ElementType, typename _MutexType = std::mutex>
22public:
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
48protected:
50 _MutexType m_mutex;
51};
52
53} // namespace lldb_private
54
55#endif // liblldb_ThreadSafeDenseSet_h_
llvm::DenseSet< _ElementType > LLVMSetType
ThreadSafeDenseSet(unsigned set_initial_capacity=0)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14