36 auto vs = validStart.
get();
37 auto ve = validEnd.
get();
56 int& startIndex2,
int& blockSize2)
const noexcept
58 auto vs = validStart.get();
59 auto ve = validEnd.get();
94 int& startIndex2,
int& blockSize2)
const noexcept
96 auto vs = validStart.get();
97 auto ve = validEnd.get();
132template <AbstractFifo::ReadOrWrite mode>
134 : startIndex1 (
other.startIndex1),
135 blockSize1 (
other.blockSize1),
136 startIndex2 (
other.startIndex2),
137 blockSize2 (
other.blockSize2)
142template <AbstractFifo::ReadOrWrite mode>
143AbstractFifo::ScopedReadWrite<mode>&
144AbstractFifo::ScopedReadWrite<mode>::operator= (ScopedReadWrite&&
other)
noexcept
150template <AbstractFifo::ReadOrWrite mode>
151void AbstractFifo::ScopedReadWrite<mode>::swap (ScopedReadWrite&
other)
noexcept
160template class AbstractFifo::ScopedReadWrite<AbstractFifo::ReadOrWrite::read>;
161template class AbstractFifo::ScopedReadWrite<AbstractFifo::ReadOrWrite::write>;
181 : Thread (
"fifo writer"), fifo (f), buffer (b),
random (
rng)
195 while (! threadShouldExit())
197 int num =
random.nextInt (2000) + 1;
199 auto writer = fifo.write (num);
201 jassert (writer.blockSize1 >= 0 && writer.blockSize2 >= 0);
202 jassert (writer.blockSize1 == 0
203 || (writer.startIndex1 >= 0 && writer.startIndex1 < fifo.getTotalSize()));
204 jassert (writer.blockSize2 == 0
205 || (writer.startIndex2 >= 0 && writer.startIndex2 < fifo.getTotalSize()));
207 writer.forEach ([
this, &n] (
int index) { this->buffer[index] = n++; });
216 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6262)
218 void runTest()
override
220 beginTest (
"AbstractFifo");
228 Random r = getRandom();
229 r.combineSeed (12345);
231 for (
int count = 100000; --
count >= 0;)
233 int num = r.nextInt (6000) + 1;
235 auto reader = fifo.read (num);
237 if (! (reader.blockSize1 >= 0 && reader.blockSize2 >= 0)
238 && (reader.blockSize1 == 0
239 || (reader.startIndex1 >= 0 && reader.startIndex1 < fifo.getTotalSize()))
240 && (reader.blockSize2 == 0
241 || (reader.startIndex2 >= 0 && reader.startIndex2 < fifo.getTotalSize())))
243 expect (
false,
"prepareToRead returned -ve values");
249 reader.forEach ([&failed, &buffer, &n] (
int index)
251 failed = (buffer[index] != n++) || failed;
256 expect (
false,
"read values were incorrect");
262 JUCE_END_IGNORE_WARNINGS_MSVC
Class for a scoped reader/writer.
ScopedReadWrite()=default
Construct an unassigned reader/writer.
void reset() noexcept
Clears the buffer positions, so that it appears empty.
void prepareToWrite(int numToWrite, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Returns the location within the buffer at which an incoming block of data should be written.
int getTotalSize() const noexcept
Returns the total size of the buffer being managed.
void prepareToRead(int numWanted, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept
Returns the location within the buffer from which the next block of data should be read.
AbstractFifo(int capacity) noexcept
Creates a FIFO to manage a buffer with the specified capacity.
void finishedRead(int numRead) noexcept
Called after reading from the FIFO, to indicate that this many items have now been consumed.
int getFreeSpace() const noexcept
Returns the number of items that can currently be added to the buffer without it overflowing.
void finishedWrite(int numWritten) noexcept
Called after writing from the FIFO, to indicate that this many items have been added.
int getNumReady() const noexcept
Returns the number of items that can currently be read from the buffer.
void setTotalSize(int newSize) noexcept
Changes the buffer's total size.
This is a base class for classes that perform a unit test.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
Type get() const noexcept
Atomically reads and returns the current value.