This library also supplies two macros, RNG_ELEM_PUT and RNG_ELEM_GET,
for putting and getting single bytes from a ring buffer. They are defined
in rngLib.h.
.CS
int RNG_ELEM_GET (ringId, pch, fromP)
int RNG_ELEM_PUT (ringId, ch, toP)
.CE
Both macros require a temporary variable or , which
should be declared as `register int’ for maximum efficiency. RNG_ELEM_GET
returns 1 if there was a character available in the buffer; it returns 0
otherwise. RNG_ELEM_PUT returns 1 if there was room in the buffer; it returns
0 otherwise. These are somewhat faster than rngBufPut() and rngBufGet(),
which can put and get multi-byte buffers.
INCLUDE FILES: rngLib.h
*/
/* LINTLIBRARY */
#include “vxWorks.h”
#include “memLib.h”
#include “rngLib.h”
#include “stdlib.h”
#include “string.h”
/*******************************************************************************
*
- rngCreate - create an empty ring buffer
- This routine creates a ring buffer of size , and initializes
- it. Memory for the buffer is allocated from the system memory partition.
- RETURNS
- The ID of the ring buffer, or NULL if memory cannot be allocated.
*/
RING_ID rngCreate
(
int nbytes /* number of bytes in ring buffer */
)
{
char *buffer;
RING_ID ringId = (RING_ID) malloc (sizeof (RING));
if (ringId == NULL)
return (NULL);
/* bump number of bytes requested because ring buffer algorithm
- always leaves at least one empty byte in buffer */
buffer = (char *) malloc ((unsigned) ++nbytes);
if (buffer == NULL)
{
free ((char *)ringId);
return (NULL);
}
ringId->bufSize = nbytes;
ringId->buf = buffer;
rngFlush (ringId);
return (ringId);
}
/*******************************************************************************
*
- rngDelete - delete a ring buffer
- This routine deletes a specified ring buffer.
- Any data currently in the buffer will be lost.
- RETURNS: N/A
*/
void rngDelete
(
FAST RING_ID ringId /* ring buffer to delete /
)
{
free (ringId->buf);
free ((char )ringId);
}
/*****************************************************************************
*
- rngFlush - make a ring buffer empty
- This routine initializes a specified ring buffer to be empty.
- Any data currently in the buffer will be lost.
- RETURNS: N/A
*/
void rngFlush
(
FAST RING_ID ringId /* ring buff