Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:46

0001 //===-- ThreadSafeDenseSet.h ------------------------------------------*- C++
0002 //-*-===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef liblldb_ThreadSafeDenseSet_h_
0011 #define liblldb_ThreadSafeDenseSet_h_
0012 
0013 #include <mutex>
0014 
0015 #include "llvm/ADT/DenseSet.h"
0016 
0017 
0018 namespace lldb_private {
0019 
0020 template <typename _ElementType, typename _MutexType = std::mutex>
0021 class ThreadSafeDenseSet {
0022 public:
0023   typedef llvm::DenseSet<_ElementType> LLVMSetType;
0024 
0025   ThreadSafeDenseSet(unsigned set_initial_capacity = 0)
0026       : m_set(set_initial_capacity), m_mutex() {}
0027 
0028   void Insert(_ElementType e) {
0029     std::lock_guard<_MutexType> guard(m_mutex);
0030     m_set.insert(e);
0031   }
0032 
0033   void Erase(_ElementType e) {
0034     std::lock_guard<_MutexType> guard(m_mutex);
0035     m_set.erase(e);
0036   }
0037 
0038   bool Lookup(_ElementType e) {
0039     std::lock_guard<_MutexType> guard(m_mutex);
0040     return (m_set.count(e) > 0);
0041   }
0042 
0043   void Clear() {
0044     std::lock_guard<_MutexType> guard(m_mutex);
0045     m_set.clear();
0046   }
0047 
0048 protected:
0049   LLVMSetType m_set;
0050   _MutexType m_mutex;
0051 };
0052 
0053 } // namespace lldb_private
0054 
0055 #endif // liblldb_ThreadSafeDenseSet_h_