MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
|
#include <ThreadQueue.h>
Public Member Functions | |
ThreadQueue () | |
~ThreadQueue () | |
void | Write (u8 *bytes, u32 length) |
void | ReadBlocking (u8 *bytes, u32 length) |
u32 | Read (u8 *bytes, u32 length) |
void | PeekRead (u8 *toBuffer, u32 index, u32 length) |
u32 | BytesAvailable () |
void | Flush () |
A thread-safe queue implementation, backed by a byte buffer of fixed length.
MFM::ThreadQueue::ThreadQueue | ( | ) |
Constructs a new ThreadQueue, setting up all mutex related structures.
MFM::ThreadQueue::~ThreadQueue | ( | ) |
Deconstructs a ThreadQueue, destroying all mutexes.
u32 MFM::ThreadQueue::BytesAvailable | ( | ) |
Gets the number of bytes currently ready to be read from the underlying queue.
void MFM::ThreadQueue::Flush | ( | ) |
Erases all held data within this TheadQueue. This should only be called in erroneous cases where the ThreadQueue should no longer need to hold any data inside. This should NEVER be used in tandem with a call to ReadBlocking; this will create a deadlock.
void MFM::ThreadQueue::PeekRead | ( | u8 * | toBuffer, |
u32 | index, | ||
u32 | length | ||
) |
Writes a series of held bytes to a specified buffer. This FAILs with ARRAY_INDEX_OUT_OF_BOUNDS if reading will go over the bounds of this ThreadQueue .
toBuffer | The buffer to read bytes from this ThreadQueue into. |
index | The byte index to begin reading from. |
length | The number of bytes to read from this ThreadQueue . |
u32 MFM::ThreadQueue::Read | ( | u8 * | bytes, |
u32 | length | ||
) |
Reads a specified number of bytes from this ThreadQueue into a specified buffer. These bytes are taken directly from the front of the underlying queue. This does not block, and instead reads as many bytes as possible from the underlying queue, up to the specified limit, before returning.
bytes | The buffer to read bytes into. This buffer will be overrwritten during this call. |
length | The number of bytes to read from the front of the underlying queue. |
void MFM::ThreadQueue::ReadBlocking | ( | u8 * | bytes, |
u32 | length | ||
) |
Reads a specified number of bytes from this ThreadQueue into a specified buffer. These bytes are taken directly from the front of the underlying queue. This blocks the calling thread until all bytes have been read.
bytes | The buffer to read bytes into. This buffer will be overrwritten during this call. |
length | The number of bytes to read from the front of the underlying queue. |
void MFM::ThreadQueue::Write | ( | u8 * | bytes, |
u32 | length | ||
) |
Writes a specified number of bytes to this ThreadQueue from a specified buffer. If writing is not available, this thread waits until it is.
bytes | The buffer where bytes will be taken from during writing. |
length | The number of bytes which will be taken from bytes. The caller must ensure that this number is less than or equal to the length of bytes. |