MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data Structures | Public Member Functions
MFM::ThreadQueue Class Reference

#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 ()
 

Detailed Description

A thread-safe queue implementation, backed by a byte buffer of fixed length.

Constructor & Destructor Documentation

MFM::ThreadQueue::ThreadQueue ( )

Constructs a new ThreadQueue, setting up all mutex related structures.

MFM::ThreadQueue::~ThreadQueue ( )

Deconstructs a ThreadQueue, destroying all mutexes.

Member Function Documentation

u32 MFM::ThreadQueue::BytesAvailable ( )

Gets the number of bytes currently ready to be read from the underlying queue.

Returns
The number of bytes 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 .

Parameters
toBufferThe buffer to read bytes from this ThreadQueue into.
indexThe byte index to begin reading from.
lengthThe 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.

Parameters
bytesThe buffer to read bytes into. This buffer will be overrwritten during this call.
lengthThe number of bytes to read from the front of the underlying queue.
Returns
The number of bytes read successfully from this call.
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.

Parameters
bytesThe buffer to read bytes into. This buffer will be overrwritten during this call.
lengthThe 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.

Parameters
bytesThe buffer where bytes will be taken from during writing.
lengthThe 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.

The documentation for this class was generated from the following files: