]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/include/lldb/Core/ThreadSafeSTLVector.h
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / include / lldb / Core / ThreadSafeSTLVector.h
1 //===-- ThreadSafeSTLVector.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_ThreadSafeSTLVector_h_
11 #define liblldb_ThreadSafeSTLVector_h_
12
13 #include <mutex>
14 #include <vector>
15
16 #include "lldb/lldb-defines.h"
17
18 namespace lldb_private {
19
20 template <typename _Object> class ThreadSafeSTLVector {
21 public:
22   typedef std::vector<_Object> collection;
23   typedef typename collection::iterator iterator;
24   typedef typename collection::const_iterator const_iterator;
25   // Constructors and Destructors
26   ThreadSafeSTLVector() : m_collection(), m_mutex() {}
27
28   ~ThreadSafeSTLVector() = default;
29
30   bool IsEmpty() const {
31     std::lock_guard<std::recursive_mutex> guard(m_mutex);
32     return m_collection.empty();
33   }
34
35   void Clear() {
36     std::lock_guard<std::recursive_mutex> guard(m_mutex);
37     return m_collection.clear();
38   }
39
40   size_t GetCount() {
41     std::lock_guard<std::recursive_mutex> guard(m_mutex);
42     return m_collection.size();
43   }
44
45   void AppendObject(_Object &object) {
46     std::lock_guard<std::recursive_mutex> guard(m_mutex);
47     m_collection.push_back(object);
48   }
49
50   _Object GetObject(size_t index) {
51     std::lock_guard<std::recursive_mutex> guard(m_mutex);
52     return m_collection.at(index);
53   }
54
55   void SetObject(size_t index, const _Object &object) {
56     std::lock_guard<std::recursive_mutex> guard(m_mutex);
57     m_collection.at(index) = object;
58   }
59
60   std::recursive_mutex &GetMutex() { return m_mutex; }
61
62 private:
63   collection m_collection;
64   mutable std::recursive_mutex m_mutex;
65
66   // For ThreadSafeSTLVector only
67   DISALLOW_COPY_AND_ASSIGN(ThreadSafeSTLVector);
68 };
69
70 } // namespace lldb_private
71
72 #endif // liblldb_ThreadSafeSTLVector_h_