30#ifndef APF_LOCKFREEFIFO_H
31#define APF_LOCKFREEFIFO_H
40template<
typename T>
class LockFreeFifo;
54 explicit LockFreeFifo(
size_t size);
61 volatile size_t _write_index;
62 volatile size_t _read_index;
64 const size_t _size_mask;
76 , _size_mask(_size - 1)
90 if (item ==
nullptr)
return false;
97 auto w = _write_index;
101 if (w < r) w += _size;
105 if (w-r > _size-2)
return false;
107 _data[w & _size_mask] = item;
110 _write_index = ++w & _size_mask;
123 if (this->empty())
return retval;
125 auto r = _read_index;
130 _read_index = ++r & _size_mask;
141 return _read_index == _write_index;
T * pop()
Get an item and remove it from the queue.
LockFreeFifo(size_t size)
ctor.
bool push(T *item)
Add an item to the queue.
bool empty() const
Check if queue is empty.
Classes derived from this class cannot be copied (but still moved).
Mathematical constants and helper functions.
Miscellaneous helper classes.
T next_power_of_2(T number)
Find a power of 2 which is >= a given number.
Audio Processing Framework.