1 //===-- ThreadSafeSTLVector.h ------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_ThreadSafeSTLVector_h_
12 #define liblldb_ThreadSafeSTLVector_h_
19 // Other libraries and framework includes
21 #include "lldb/lldb-defines.h"
23 namespace lldb_private {
25 template <typename _Object> class ThreadSafeSTLVector {
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() {}
35 ~ThreadSafeSTLVector() = default;
37 bool IsEmpty() const {
38 std::lock_guard<std::recursive_mutex> guard(m_mutex);
39 return m_collection.empty();
43 std::lock_guard<std::recursive_mutex> guard(m_mutex);
44 return m_collection.clear();
48 std::lock_guard<std::recursive_mutex> guard(m_mutex);
49 return m_collection.size();
52 void AppendObject(_Object &object) {
53 std::lock_guard<std::recursive_mutex> guard(m_mutex);
54 m_collection.push_back(object);
57 _Object GetObject(size_t index) {
58 std::lock_guard<std::recursive_mutex> guard(m_mutex);
59 return m_collection.at(index);
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;
67 std::recursive_mutex &GetMutex() { return m_mutex; }
70 collection m_collection;
71 mutable std::recursive_mutex m_mutex;
73 //------------------------------------------------------------------
74 // For ThreadSafeSTLVector only
75 //------------------------------------------------------------------
76 DISALLOW_COPY_AND_ASSIGN(ThreadSafeSTLVector);
79 } // namespace lldb_private
81 #endif // liblldb_ThreadSafeSTLVector_h_