Group PJ_FIFOBUF

group PJ_FIFOBUF

Functions

void pj_fifobuf_init(pj_fifobuf_t *fb, void *buffer, unsigned size)

Initialize the fifobuf by giving it a buffer and size.

Parameters:
  • fb – The fifobuf

  • buffer – Buffer to be used to allocate/free chunks of memory from by the fifo buffer.

  • size – The size of the buffer.

unsigned pj_fifobuf_capacity(pj_fifobuf_t *fb)

Returns the capacity (initial size) of the buffer.

Parameters:

fb – The fifobuf

Returns:

Capacity in bytes.

unsigned pj_fifobuf_available_size(pj_fifobuf_t *fb)

Returns maximum size of memory chunk that can be allocated from the buffer.

Parameters:

fb – The fifobuf

Returns:

Size in bytes

void *pj_fifobuf_alloc(pj_fifobuf_t *fb, unsigned size)

Allocate a chunk of memory from the fifobuf.

Parameters:
  • fb – The fifobuf

  • size – Size to allocate

Returns:

Allocated buffer or NULL if the buffer cannot be allocated

pj_status_t pj_fifobuf_free(pj_fifobuf_t *fb, void *buf)

Return the space used by the earliest allocated memory chunk back to the fifobuf. For example, if app previously allocated ptr0, ptr1, and ptr2 (in that order), then pj_fifobuf_free() can only be called with ptr0 as parameter. Subsequent pj_fifobuf_free() must be called with ptr1, and the next one with ptr2, and so on.

Parameters:
  • fb – The fifobuf

  • buf – Pointer to memory chunk previously returned by pj_fifobuf_alloc()

Returns:

PJ_SUCCESS or the appropriate error.

struct pj_fifobuf_t
#include <fifobuf.h>

A FIFO buffer provides chunks of memory to the application with first in first out policy (or more correctly, first out first in). The fifobuf is created by providing it with a fixed buffer. After that, application may request chunks of memory from this buffer. When the app is done with a chunk of memory, it must return that chunk back to the fifobuf, with the requirement that the oldest allocated chunk must be returned first.

Public Members

char *first

The start of the buffer

char *last

The end of the buffer

char *ubegin

The start of used area in the buffer

char *uend

The end of used area in the buffer

int full

Full flag when ubegin==uend