]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ThreadSafeSTLVector.h
MFV r331405: 9084 spa_*_ashift must ignore spare devices
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / ThreadSafeSTLVector.h
1 //===-- ThreadSafeSTLVector.h ------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef liblldb_ThreadSafeSTLVector_h_
12 #define liblldb_ThreadSafeSTLVector_h_
13
14 // C Includes
15 // C++ Includes
16 #include <mutex>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/lldb-defines.h"
22
23 namespace lldb_private {
24
25 template <typename _Object> class ThreadSafeSTLVector {
26 public:
27   typedef std::vector<_Object> collection;
28   typedef typename collection::iterator iterator;
29   typedef typename collection::const_iterator const_iterator;
30   //------------------------------------------------------------------
31   // Constructors and Destructors
32   //------------------------------------------------------------------
33   ThreadSafeSTLVector() : m_collection(), m_mutex() {}
34
35   ~ThreadSafeSTLVector() = default;
36
37   bool IsEmpty() const {
38     std::lock_guard<std::recursive_mutex> guard(m_mutex);
39     return m_collection.empty();
40   }
41
42   void Clear() {
43     std::lock_guard<std::recursive_mutex> guard(m_mutex);
44     return m_collection.clear();
45   }
46
47   size_t GetCount() {
48     std::lock_guard<std::recursive_mutex> guard(m_mutex);
49     return m_collection.size();
50   }
51
52   void AppendObject(_Object &object) {
53     std::lock_guard<std::recursive_mutex> guard(m_mutex);
54     m_collection.push_back(object);
55   }
56
57   _Object GetObject(size_t index) {
58     std::lock_guard<std::recursive_mutex> guard(m_mutex);
59     return m_collection.at(index);
60   }
61
62   void SetObject(size_t index, const _Object &object) {
63     std::lock_guard<std::recursive_mutex> guard(m_mutex);
64     m_collection.at(index) = object;
65   }
66
67   std::recursive_mutex &GetMutex() { return m_mutex; }
68
69 private:
70   collection m_collection;
71   mutable std::recursive_mutex m_mutex;
72
73   //------------------------------------------------------------------
74   // For ThreadSafeSTLVector only
75   //------------------------------------------------------------------
76   DISALLOW_COPY_AND_ASSIGN(ThreadSafeSTLVector);
77 };
78
79 } // namespace lldb_private
80
81 #endif // liblldb_ThreadSafeSTLVector_h_