glbinding  3.3.0.0
A C++ binding for the OpenGL API, generated using the gl.xml specification.
Loading...
Searching...
No Matches
RingBuffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <iterator>
5#include <map>
6#include <vector>
7
8
9namespace glbinding { namespace aux
10{
11
12
20template <typename T>
22{
23
24public:
25 // Buffer is limited to (maxValue(sizeType)/2 - 1) entries
26 using SizeType = unsigned int;
27 using TailIdentifier = unsigned int;
28
37
45 void resize(SizeType newSize);
46
57 T nextHead(bool & available) const;
58
69 bool push(T && entry);
70
81 bool push(T & entry);
82
91
99 void removeTail(TailIdentifier key);
100
114 const typename std::vector<T>::const_iterator cbegin(TailIdentifier key) const;
115
129 bool valid(TailIdentifier key, const typename std::vector<T>::const_iterator & it) const;
130
144 const typename std::vector<T>::const_iterator next(TailIdentifier key, const typename std::vector<T>::const_iterator & it);
145
157
165 SizeType maxSize() const;
166
174 SizeType size() const;
175
183 bool isFull() const;
184
192 bool isEmpty() const;
193
194protected:
205 SizeType next(SizeType current) const;
206
217 bool isFull(SizeType nextHead) const;
218
226 SizeType lastTail() const;
227
241 SizeType size(SizeType head, SizeType tail) const;
242
243protected:
244 std::vector<T> m_buffer;
246 std::atomic<SizeType> m_head;
247 std::map<TailIdentifier, std::atomic<SizeType>> m_tails;
248};
249
250
251} } // namespace glbinding::aux
252
253
A threadsafe queue with a single insertion and multiple extraction points.
Definition RingBuffer.h:22
SizeType size() const
Query current size.
Definition RingBuffer.inl:171
std::vector< T > m_buffer
Internal buffer.
Definition RingBuffer.h:244
TailIdentifier addTail()
Add a new tail to the buffer.
Definition RingBuffer.inl:101
bool valid(TailIdentifier key, const typename std::vector< T >::const_iterator &it) const
Check if iterator is valid.
Definition RingBuffer.inl:130
void removeTail(TailIdentifier key)
Remove a tail from the buffer.
Definition RingBuffer.inl:113
unsigned int SizeType
Numeric type employed for indices, sizes and distances.
Definition RingBuffer.h:26
SizeType lastTail() const
Determine last (furthest behind) index still in use.
Definition RingBuffer.inl:220
unsigned int TailIdentifier
Identifier type for tails.
Definition RingBuffer.h:27
void resize(SizeType newSize)
Resize buffer.
Definition RingBuffer.inl:23
bool push(T &&entry)
Add an element to the buffer, if possible.
Definition RingBuffer.inl:46
RingBuffer(SizeType maxSize)
Constructor.
Definition RingBuffer.inl:15
std::map< TailIdentifier, std::atomic< SizeType > > m_tails
Map (identifier->index) of tails.
Definition RingBuffer.h:247
bool isFull() const
Query if buffer is full.
Definition RingBuffer.inl:180
T nextHead(bool &available) const
Retrieve element beyond current head.
Definition RingBuffer.inl:30
bool isEmpty() const
Query if buffer is empty.
Definition RingBuffer.inl:189
const std::vector< T >::const_iterator next(TailIdentifier key, const typename std::vector< T >::const_iterator &it)
Advance the iterator of a tail.
Definition RingBuffer.inl:139
const std::vector< T >::const_iterator cbegin(TailIdentifier key) const
Retrieve the iterator for a tail.
Definition RingBuffer.inl:119
SizeType m_size
Size of buffer.
Definition RingBuffer.h:245
std::atomic< SizeType > m_head
Index of head (newest element)
Definition RingBuffer.h:246
SizeType maxSize() const
Query maximum size.
Definition RingBuffer.inl:165
Contains all the classes of glbinding.