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 /// Returns true if \p e was not in the set yet.
29 bool Insert(_ElementType e) {
30 std::lock_guard<_MutexType> guard(m_mutex);
31 return m_set.insert(e).second;
32 }
33
34 void Erase(_ElementType e) {
35 std::lock_guard<_MutexType> guard(m_mutex);
36 m_set.erase(e);
37 }
38
39 bool Lookup(_ElementType e) {
40 std::lock_guard<_MutexType> guard(m_mutex);
41 return (m_set.count(e) > 0);
42 }
43
44 void Clear() {
45 std::lock_guard<_MutexType> guard(m_mutex);
46 m_set.clear();
47 }
48
49protected:
51 _MutexType m_mutex;
52};
53
54} // namespace lldb_private
55
56#endif // liblldb_ThreadSafeDenseSet_h_
llvm::DenseSet< _ElementType > LLVMSetType
bool Insert(_ElementType e)
Returns true if e was not in the set yet.
ThreadSafeDenseSet(unsigned set_initial_capacity=0)
A class that represents a running process on the host machine.