6namespace wmtk::threading {
16 std::vector<T> m_data;
17 mutable std::mutex m_mutex;
21 using iterator =
typename std::vector<T>::iterator;
22 using const_iterator =
typename std::vector<T>::const_iterator;
23 using reference =
typename std::vector<T>::reference;
24 using const_reference =
typename std::vector<T>::const_reference;
48 std::lock_guard<std::mutex> lock(m_mutex);
53 std::lock_guard<std::mutex> lock(m_mutex);
54 m_data.push_back(std::move(v));
62 template <
typename... Args>
65 std::lock_guard<std::mutex> lock(m_mutex);
66 m_data.emplace_back(std::forward<Args>(args)...);
76 std::lock_guard<std::mutex> lock(m_mutex);
77 m_data.insert(m_data.end(), v.begin(), v.end());
87 std::lock_guard<std::mutex> lock(m_mutex);
90 void resize(std::size_t n,
const T& value)
92 std::lock_guard<std::mutex> lock(m_mutex);
93 m_data.resize(n, value);
101 std::lock_guard<std::mutex> lock(m_mutex);
111 std::lock_guard<std::mutex> lock(m_mutex);
120 const std::vector<T>&
data()
const {
return m_data; }
128 const_reference
operator[](std::size_t i)
const {
return m_data[i]; }
136 std::size_t
size()
const {
return m_data.size(); }
142 bool empty()
const {
return m_data.empty(); }
146 const_iterator begin()
const {
return m_data.begin(); }
147 const_iterator end()
const {
return m_data.end(); }
Definition collector.hpp:15
void clear()
Clear the collector. This function is thread-safe.
Definition collector.hpp:99
bool empty() const
Check if the collector is empty. This function is NOT thread-safe.
Definition collector.hpp:142
const_reference operator[](std::size_t i) const
operator[] is not thread-safe for concurrent writes, but is safe for concurrent reads after all write...
Definition collector.hpp:128
const std::vector< T > & data() const
Get the underlying data vector. This function is NOT thread-safe.
Definition collector.hpp:120
void emplace_back(Args &&... args)
Emplace an element at the end of the collector. This function is thread-safe.
Definition collector.hpp:63
void append(const std::vector< T > &v)
Append a vector of elements to the end of the collector. This function is thread-safe.
Definition collector.hpp:74
std::size_t size() const
Get the number of elements in the collector. This function is NOT thread-safe.
Definition collector.hpp:136
void reserve(std::size_t n)
Reserve space in the collector. This function is thread-safe.
Definition collector.hpp:109
void push_back(const T &v)
Push an element to the end of the collector. This function is thread-safe.
Definition collector.hpp:46
void resize(std::size_t n)
Resize the collector to contain n elements. This function is thread-safe.
Definition collector.hpp:85