95 const auto startPos = (readPos + numReadable) & (size - 1);
97 const auto firstBlockSize =
jmin (maxToWrite, size - startPos);
99 numReadable += maxToWrite;
101 return { { { startPos, startPos + firstBlockSize }, { 0, maxToWrite - firstBlockSize } } };
111 const auto startPos = readPos;
112 const auto maxToRead =
jmin (numReadable, num);
113 const auto firstBlockSize =
jmin (maxToRead, size - startPos);
115 readPos = (startPos + maxToRead) & (size - 1);
116 numReadable -= maxToRead;
118 return { { { startPos, startPos + firstBlockSize }, { 0, maxToRead - firstBlockSize } } };
122 int size = 0, readPos = 0, numReadable = 0;
Encapsulates the logic for a single-threaded FIFO.
SingleThreadedAbstractFifo(int sizeIn)
Creates a SingleThreadedAbstractFifo that can manage a buffer of the specified size.
SingleThreadedAbstractFifo()=default
Creates a SingleThreadedAbstractFifo with no size.
int getRemainingSpace() const
Returns the number of unused elements present in the buffer.
std::array< Range< int >, 2 > read(int num)
Returns two blocks in the buffer from which new items may be read.
int getSize() const
Returns the size of the managed buffer.
std::array< Range< int >, 2 > write(int num)
Returns two blocks in the buffer where new items may be written.
int getNumReadable() const
Returns the number of pending elements present in the buffer.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr bool isPowerOfTwo(IntegerType value)
Returns true if the specified integer is a power-of-two.