12 inline WaitRing<T>::WaitRing(
size_t capacity) : _closed(false), _capacity(capacity - 1), _mask(capacity - 1), _head(0), _tail(0), _ring(capacity)
14 assert((
capacity > 1) &&
"Ring capacity must be greater than one!");
15 assert(((
capacity & (
capacity - 1)) == 0) &&
"Ring capacity must be a power of two!");
42 return Enqueue(std::forward<T>(temp));
55 if (((_head - _tail + 1) & _mask) != 0)
57 _ring[_head++ & _mask] = std::move(item);
62 _cv2.Wait(_cs, [
this]() {
return (_closed || (((_head - _tail + 1) & _mask) != 0)); });
74 if (_closed && (((_head - _tail) & _mask) == 0))
79 if (((_head - _tail) & _mask) != 0)
81 item = std::move(_ring[_tail++ & _mask]);
86 _cv1.Wait(_cs, [
this]() {
return (_closed || (((_head - _tail) & _mask) != 0)); });
88 }
while (!_closed || (((_head - _tail) & _mask) != 0));
Locker synchronization primitive.
bool closed() const
Is wait ring closed?
size_t capacity() const
Get wait ring capacity.
WaitRing(size_t capacity)
Default class constructor.
bool Enqueue(const T &item)
Enqueue an item into the wait ring.
bool Dequeue(T &item)
Dequeue an item from the wait ring.
size_t size() const
Get wait ring size.
void Close()
Close the wait ring.
C++ Common project definitions.