VxWorks Reference Manual : Wind Foundation Classes

VXWRingBuf

NAME

VXWRingBuf - ring buffer class

METHODS

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

DESCRIPTION

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).

INCLUDE FILES

vxwRngLib.h

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::VXWRingBuf( )

NAME

VXWRingBuf::VXWRingBuf( ) - create an empty ring buffer

SYNOPSIS

VXWRingBuf
    (
    int nbytes
    )

DESCRIPTION

This constructor creates a ring buffer of size nbytes, and initializes it. Memory for the buffer is allocated from the system memory partition.

RETURNS

N/A.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::VXWRingBuf( )

NAME

VXWRingBuf::VXWRingBuf( ) - build ring-buffer object from existing ID

SYNOPSIS

VXWRingBuf
    (
    RING_ID aRingId
    )

DESCRIPTION

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.

RETURNS

N/A.

SEE ALSO

VXWRingBuf, rngLib


Wind Foundation Classes : Methods

VXWRingBuf::~VXWRingBuf( )

NAME

VXWRingBuf::~VXWRingBuf( ) - delete ring buffer

SYNOPSIS

    ~VXWRingBuf ()

DESCRIPTION

This destructor deletes a specified ring buffer. Any data in the buffer at the time it is deleted is lost.

RETURNS

N/A

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::get( )

NAME

VXWRingBuf::get( ) - get characters from ring buffer

SYNOPSIS

int get
    (
    char * buffer,
    int    maxbytes
    )

DESCRIPTION

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.

RETURNS

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.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::put( )

NAME

VXWRingBuf::put( ) - put bytes into ring buffer

SYNOPSIS

int put
    (
    char * buffer,
    int    nBytes
    )

DESCRIPTION

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.

RETURNS

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.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::flush( )

NAME

VXWRingBuf::flush( ) - make ring buffer empty

SYNOPSIS

    void flush ()

DESCRIPTION

This routine initializes the ring buffer to be empty. Any data in the buffer is lost.

RETURNS

N/A

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::freeBytes( )

NAME

VXWRingBuf::freeBytes( ) - determine the number of free bytes in ring buffer

SYNOPSIS

    int freeBytes ()

DESCRIPTION

This routine determines the number of bytes currently unused in the ring buffer.

RETURNS

The number of unused bytes in the ring buffer.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::isEmpty( )

NAME

VXWRingBuf::isEmpty( ) - test whether ring buffer is empty

SYNOPSIS

    BOOL isEmpty ()

DESCRIPTION

This routine reports on whether the ring buffer is empty.

RETURNS

TRUE if empty, FALSE if not.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::isFull( )

NAME

VXWRingBuf::isFull( ) - test whether ring buffer is full (no more room)

SYNOPSIS

    BOOL isFull ()

DESCRIPTION

This routine reports on whether the ring buffer is completely full.

RETURNS

TRUE if full, FALSE if not.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::moveAhead( )

NAME

VXWRingBuf::moveAhead( ) - advance ring pointer by n bytes

SYNOPSIS

void moveAhead
    (
    int n
    )

DESCRIPTION

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

RETURNS

N/A

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::nBytes( )

NAME

VXWRingBuf::nBytes( ) - determine the number of bytes in ring buffer

SYNOPSIS

    int nBytes ()

DESCRIPTION

This routine determines the number of bytes currently in the ring buffer.

RETURNS

The number of bytes filled in the ring buffer.

SEE ALSO

VXWRingBuf


Wind Foundation Classes : Methods

VXWRingBuf::putAhead( )

NAME

VXWRingBuf::putAhead( ) - put a byte ahead in a ring buffer without moving ring pointers

SYNOPSIS

void putAhead
    (
    char byte,
    int  offset
    )

DESCRIPTION

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.

RETURNS

N/A

SEE ALSO

VXWRingBuf