High Performance OPC UA Server SDK  1.2.0.193
ringqueue

A queue that is implemented as a ring buffer. More...

Data Structures

struct  util_ringqueue
 Structure for the ringqueue, see also ringqueue. More...
 

Macros

#define util_ringqueue_foreach(i, queue)   for (i = util_ringqueue_index_first(queue); i != -1; i = util_ringqueue_index_next(queue, i))
 Foreach loop for iterating through a ringqueue.
 

Functions

int util_ringqueue_size (int num_elements)
 Computes the size in bytes for num_elements ringqueue entries. More...
 
void util_ringqueue_init (struct util_ringqueue *queue, void *data, int size)
 Initializes a ringqueue. More...
 
void * util_ringqueue_clear (struct util_ringqueue *queue)
 Clear the ringqueue queue. More...
 
unsigned int util_ringqueue_count (struct util_ringqueue *queue)
 Get the current number of elements in a ringqueue.
 
bool util_ringqueue_full (struct util_ringqueue *queue)
 Test if the ringqueue queue is full. More...
 
unsigned int util_ringqueue_max (struct util_ringqueue *queue)
 Get the maximum capacity of a queue.
 
int util_ringqueue_put_front (struct util_ringqueue *queue, void *data)
 Insert an element data at the front of the ringqueue queue. More...
 
int util_ringqueue_put_end (struct util_ringqueue *queue, void *data)
 Insert an element data at the end of the ringqueue queue. More...
 
void * util_ringqueue_pop_front (struct util_ringqueue *queue)
 Remove an element at the front of the ringqueue queue. More...
 
void * util_ringqueue_pop_end (struct util_ringqueue *queue)
 Remove an element at the end of the ringqueue queue. More...
 
int util_ringqueue_index_first (struct util_ringqueue *queue)
 Get the index to the first element of the queue. More...
 
int util_ringqueue_index_next (struct util_ringqueue *queue, int idx)
 Get the index to the next element of the queue. More...
 
void * util_ringqueue_get_index (struct util_ringqueue *queue, int idx)
 Get the element at a given index idx of the queue. More...
 
void * util_ringqueue_get_front (struct util_ringqueue *queue)
 Get the element at the front of the queue. More...
 
void * util_ringqueue_get_end (struct util_ringqueue *queue)
 Get the element at the end of the queue. More...
 

Detailed Description

A queue that is implemented as a ring buffer.

Allows to store arbitrary number of elements, however internal buffer must be provided by user. It is possible to add and remove elements at front and back of the queue.

Function Documentation

void* util_ringqueue_clear ( struct util_ringqueue queue)

Clear the ringqueue queue.

Returns
The data pointer that was given to util_ringqueue_init, as it might need to be freed.
bool util_ringqueue_full ( struct util_ringqueue queue)

Test if the ringqueue queue is full.

Returns
True if no further elements can be added.
void* util_ringqueue_get_end ( struct util_ringqueue queue)

Get the element at the end of the queue.

Returns
Pointer to last element or NULL if queue is empty.
void* util_ringqueue_get_front ( struct util_ringqueue queue)

Get the element at the front of the queue.

Returns
Pointer to first element or NULL if queue is empty.
void* util_ringqueue_get_index ( struct util_ringqueue queue,
int  idx 
)

Get the element at a given index idx of the queue.

Returns
Pointer to element at index or NULL if queue is empty.
int util_ringqueue_index_first ( struct util_ringqueue queue)

Get the index to the first element of the queue.

Returns
Index or negative errorcode if queue is empty.
int util_ringqueue_index_next ( struct util_ringqueue queue,
int  idx 
)

Get the index to the next element of the queue.

Returns
Index or negative errorcode if queue is empty.
void util_ringqueue_init ( struct util_ringqueue queue,
void *  data,
int  size 
)

Initializes a ringqueue.

Parameters
queueThe ringqueue context.
dataPointer to preallocated memory to use for the ringqueue.
sizeSize of data in bytes, see util_list_size.
void* util_ringqueue_pop_end ( struct util_ringqueue queue)

Remove an element at the end of the ringqueue queue.

Returns
Pointer to element that was removed or NULL when queue is empty.
void* util_ringqueue_pop_front ( struct util_ringqueue queue)

Remove an element at the front of the ringqueue queue.

Returns
Pointer to element that was removed or NULL when queue is empty.
int util_ringqueue_put_end ( struct util_ringqueue queue,
void *  data 
)

Insert an element data at the end of the ringqueue queue.

Returns
Zero on success or errorcode on failure.
int util_ringqueue_put_front ( struct util_ringqueue queue,
void *  data 
)

Insert an element data at the front of the ringqueue queue.

Returns
Zero on success or errorcode on failure.
int util_ringqueue_size ( int  num_elements)

Computes the size in bytes for num_elements ringqueue entries.

This can be used by the called to allocate the correct amount of memory for util_ringqueue_init.