1 //===-- ThreadSafeSTLVector.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadSafeSTLVector_h_
11 #define liblldb_ThreadSafeSTLVector_h_
18 // Other libraries and framework includes
20 #include "lldb/lldb-defines.h"
22 namespace lldb_private {
24 template <typename _Object>
25 class ThreadSafeSTLVector
28 typedef std::vector<_Object> collection;
29 typedef typename collection::iterator iterator;
30 typedef typename collection::const_iterator const_iterator;
31 //------------------------------------------------------------------
32 // Constructors and Destructors
33 //------------------------------------------------------------------
34 ThreadSafeSTLVector() : m_collection(), m_mutex() {}
36 ~ThreadSafeSTLVector() = default;
41 std::lock_guard<std::recursive_mutex> guard(m_mutex);
42 return m_collection.empty();
48 std::lock_guard<std::recursive_mutex> guard(m_mutex);
49 return m_collection.clear();
55 std::lock_guard<std::recursive_mutex> guard(m_mutex);
56 return m_collection.size();
60 AppendObject (_Object& object)
62 std::lock_guard<std::recursive_mutex> guard(m_mutex);
63 m_collection.push_back(object);
67 GetObject (size_t index)
69 std::lock_guard<std::recursive_mutex> guard(m_mutex);
70 return m_collection.at(index);
74 SetObject (size_t index, const _Object& object)
76 std::lock_guard<std::recursive_mutex> guard(m_mutex);
77 m_collection.at(index) = object;
80 std::recursive_mutex &
87 collection m_collection;
88 mutable std::recursive_mutex m_mutex;
90 //------------------------------------------------------------------
91 // For ThreadSafeSTLVector only
92 //------------------------------------------------------------------
93 DISALLOW_COPY_AND_ASSIGN (ThreadSafeSTLVector);
97 } // namespace lldb_private
99 #endif // liblldb_ThreadSafeSTLVector_h_