26 m_buffer.resize(m_size);
32 const auto head = m_head.load(std::memory_order_relaxed);
33 const auto nextHead = next(head);
42 return m_buffer[nextHead];
48 const auto head = m_head.load(std::memory_order_relaxed);
49 const auto nextHead = next(head);
56 assert(head < m_size);
58 if (m_buffer.size() <= head)
61 m_buffer.push_back(entry);
65 m_buffer[head] = entry;
68 m_head.store(nextHead, std::memory_order_release);
76 auto head = m_head.load(std::memory_order_relaxed);
77 auto nextHead = next(head);
84 assert(head < m_size);
86 if (m_buffer.size() <= head)
88 m_buffer.push_back(entry);
92 m_buffer[head] = entry;
95 m_head.store(nextHead, std::memory_order_release);
104 const auto it = m_tails.rbegin();
105 const auto i =
TailIdentifier(it == m_tails.rend() ? 0 : it->first + 1);
107 m_tails[i] = m_head.load(std::memory_order_acquire);
121 auto tail = m_tails.at(key).load(std::memory_order_relaxed);
122 auto i = m_buffer.cbegin();
124 std::advance(i, tail);
132 auto pos = std::abs(std::distance(m_buffer.cbegin(), it));
133 auto head = m_head.load(std::memory_order_acquire);
135 return (
static_cast<SizeType>(pos) != head);
141 auto tail = m_tails[key].load(std::memory_order_acquire);
143 if (tail == m_head.load(std::memory_order_acquire))
148 auto nextTail = next(tail);
150 m_tails[key].store(nextTail, std::memory_order_release);
158 auto head = m_head.load(std::memory_order_acquire);
159 auto tail = m_tails[key].load(std::memory_order_acquire);
161 return size(head, tail);
173 auto head = m_head.load(std::memory_order_acquire);
174 auto tail = lastTail();
176 return size(head, tail);
182 auto head = m_head.load(std::memory_order_relaxed);
183 auto nextHead = next(head);
185 return isFull(nextHead);
191 auto tail = lastTail();
193 return tail == m_head.load(std::memory_order_acquire);
202 return (current + 1) % m_size;
208 for (
auto it = m_tails.cbegin(); it != m_tails.cend(); ++it)
210 auto tailPos = it->second.load(std::memory_order_acquire);
212 if (nextHead == tailPos)
222 auto head = m_head.load(std::memory_order_relaxed);
223 auto last = head + m_size;
225 for (
auto it = m_tails.cbegin(); it != m_tails.cend(); ++it)
227 auto tailPos = it->second.load(std::memory_order_acquire);
235 return last % m_size;
243 return m_size - tail + head;
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
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
SizeType maxSize() const
Query maximum size.
Definition RingBuffer.inl:165
Contains all the classes of glbinding.