VxWorks Reference Manual : Wind Foundation Classes
VXWRingBuf - ring buffer class
VXWRingBuf::VXWRingBuf( ) - create an empty ring buffer
VXWRingBuf::VXWRingBuf( ) - build ring-buffer object from existing ID
VXWRingBuf::~VXWRingBuf( ) - delete ring buffer
VXWRingBuf::get( ) - get characters from ring buffer
VXWRingBuf::put( ) - put bytes into ring buffer
VXWRingBuf::flush( ) - make ring buffer empty
VXWRingBuf::freeBytes( ) - determine the number of free bytes in ring buffer
VXWRingBuf::isEmpty( ) - test whether ring buffer is empty
VXWRingBuf::isFull( ) - test whether ring buffer is full (no more room)
VXWRingBuf::moveAhead( ) - advance ring pointer by n bytes
VXWRingBuf::nBytes( ) - determine the number of bytes in ring buffer
VXWRingBuf::putAhead( ) - put a byte ahead in a ring buffer without moving ring pointers
The VXWRingBuf class provides routines for creating and using ring buffers, which are first-in-first-out circular buffers. The routines simply manipulate the ring buffer data structure; no kernel functions are invoked. In particular, ring buffers by themselves provide no task synchronization or mutual exclusion.
However, the ring buffer pointers are manipulated in such a way that a reader task (invoking VXWRingBuf::get( )) and a writer task (invoking VXWRingBuf::put( )) can access a ring simultaneously without requiring mutual exclusion. This is because readers only affect a read pointer and writers only affect a write pointer in a ring buffer data structure. However, access by multiple readers or writers must be interlocked through a mutual exclusion mechanism (for example, a mutual-exclusion semaphore guarding a ring buffer).
vxwRngLib.h
VXWRingBuf::VXWRingBuf( ) - create an empty ring buffer
VXWRingBuf ( int nbytes )
This constructor creates a ring buffer of size nbytes, and initializes it. Memory for the buffer is allocated from the system memory partition.
N/A.
VXWRingBuf::VXWRingBuf( ) - build ring-buffer object from existing ID
VXWRingBuf ( RING_ID aRingId )
Use this constructor to build a ring-buffer object from an existing ring buffer. This permits you to use the C++ ring-buffer interfaces even if the ring buffer itself was created by a routine written in C.
N/A.
VXWRingBuf::~VXWRingBuf( ) - delete ring buffer
~VXWRingBuf ()
This destructor deletes a specified ring buffer. Any data in the buffer at the time it is deleted is lost.
N/A
VXWRingBuf::get( ) - get characters from ring buffer
int get ( char * buffer, int maxbytes )
This routine copies bytes from the ring buffer into buffer. It copies as many bytes as are available in the ring, up to maxbytes. The bytes copied are then removed from the ring.
The number of bytes actually received from the ring buffer; it may be zero if the ring buffer is empty at the time of the call.
VXWRingBuf::put( ) - put bytes into ring buffer
int put ( char * buffer, int nBytes )
This routine puts bytes from buffer into the ring buffer. The specified number of bytes is put into the ring, up to the number of bytes available in the ring.
The number of bytes actually put into the ring buffer; it may be less than number requested, even zero, if there is insufficient room in the ring buffer at the time of the call.
VXWRingBuf::flush( ) - make ring buffer empty
void flush ()
This routine initializes the ring buffer to be empty. Any data in the buffer is lost.
N/A
VXWRingBuf::freeBytes( ) - determine the number of free bytes in ring buffer
int freeBytes ()
This routine determines the number of bytes currently unused in the ring buffer.
The number of unused bytes in the ring buffer.
VXWRingBuf::isEmpty( ) - test whether ring buffer is empty
BOOL isEmpty ()
This routine reports on whether the ring buffer is empty.
TRUE if empty, FALSE if not.
VXWRingBuf::isFull( ) - test whether ring buffer is full (no more room)
BOOL isFull ()
This routine reports on whether the ring buffer is completely full.
TRUE if full, FALSE if not.
VXWRingBuf::moveAhead( ) - advance ring pointer by n bytes
void moveAhead ( int n )
This routine advances the ring buffer input pointer by n bytes. This makes n bytes available in the ring buffer, after having been written ahead in the ring buffer with VXWRingBuf::putAhead( ).
N/A
VXWRingBuf::nBytes( ) - determine the number of bytes in ring buffer
int nBytes ()
This routine determines the number of bytes currently in the ring buffer.
The number of bytes filled in the ring buffer.
VXWRingBuf::putAhead( ) - put a byte ahead in a ring buffer without moving ring pointers
void putAhead ( char byte, int offset )
This routine writes a byte into the ring, but does not move the ring buffer pointers. Thus the byte is not yet be available to VXWRingBuf::get( ) calls. The byte is written offset bytes ahead of the next input location in the ring. Thus, an offset of 0 puts the byte in the same position as VXWRingBuf::put( ) would put a byte, except that the input pointer is not updated.
Bytes written ahead in the ring buffer with this routine can be made available all at once by subsequently moving the ring buffer pointers with the routine VXWRingBuf::moveAhead( ).
Before calling VXWRingBuf::putAhead( ), the caller must verify that at least offset + 1 bytes are available in the ring buffer.
N/A