HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
queue.c File Reference
#include <hipc/atomic.h>
#include <hipc/queue.h>
Include dependency graph for queue.c:

Go to the source code of this file.

Functions

void hipcQueueInit (struct HIPC_queue *const que_p, void *const buf_p, const size_t item_size, const size_t n_slot)
 Initializes a queue. More...
 
size_t hipcQueueItemSize (struct HIPC_queue *const que_p)
 Gets item size. More...
 
void * hipcQueueEmpty (struct HIPC_queue *const que_p)
 Returns an address of the head item if it exists. More...
 
void hipcQueuePop (struct HIPC_queue *const que_p)
 Pops an item and releases a slot. More...
 
void * hipcQueueFull (struct HIPC_queue const *const que_p)
 Returns an address of an empty slot if it exists. More...
 
void hipcQueuePush (struct HIPC_queue *const que_p)
 Pushes an item and occupies a slot. More...
 
void hipcQueueClear (struct HIPC_queue *const que_p)
 Clears a queue. More...
 

Function Documentation

void hipcQueueInit ( struct HIPC_queue *const  que_p,
void *const  buf_p,
const size_t  item_size,
const size_t  n_slot 
)

Initializes a queue.

Parameters
que_ppointer to a queue
buf_pa buffer whose size must be item_size multiplied by n_slot
item_sizesize of an item
n_slotnumber of slots

Definition at line 12 of file queue.c.

References HIPC_queue::buf_p, HIPC_queue::head, HIPC_MEM_BARRIER, HIPC_queue::item_size, HIPC_queue::n_slot, and HIPC_queue::tail.

size_t hipcQueueItemSize ( struct HIPC_queue *const  que_p)

Gets item size.

Parameters
que_ppointer to a queue
Returns
item size

Definition at line 32 of file queue.c.

References HIPC_queue::item_size.

void* hipcQueueEmpty ( struct HIPC_queue *const  que_p)

Returns an address of the head item if it exists.

Parameters
que_ppointer to a queue
Returns
NULL when the queue is empty, otherwise an address of an item to be popped is returned.

Definition at line 44 of file queue.c.

References HIPC_queue::buf_p, HIPC_queue::head, HIPC_queue::item_size, and HIPC_queue::tail.

void hipcQueuePop ( struct HIPC_queue *const  que_p)

Pops an item and releases a slot.

Before each pop, it must be checked that a queue is not empty by hipcQueueEmpty().

Parameters
que_ppointer to a queue

Definition at line 61 of file queue.c.

References HIPC_queue::head, HIPC_MEM_BARRIER, and HIPC_queue::n_slot.

void* hipcQueueFull ( struct HIPC_queue const *const  que_p)

Returns an address of an empty slot if it exists.

Parameters
que_ppointer to a queue
Returns
NULL when the queue is full, otherwise an address of an item to be pushed is returned.

Definition at line 76 of file queue.c.

References HIPC_queue::buf_p, HIPC_queue::head, HIPC_queue::item_size, HIPC_queue::n_slot, and HIPC_queue::tail.

void hipcQueuePush ( struct HIPC_queue *const  que_p)

Pushes an item and occupies a slot.

Before each push, it must be checked that a queue is not full by hipcQueueFull().

Parameters
que_ppointer to a queue

Definition at line 93 of file queue.c.

References HIPC_MEM_BARRIER, HIPC_queue::n_slot, and HIPC_queue::tail.

void hipcQueueClear ( struct HIPC_queue *const  que_p)

Clears a queue.

Only a consumer, not a producer, should call this function because the consumer may still use a slot.

Parameters
que_ppointer to a queue

Definition at line 108 of file queue.c.

References HIPC_queue::head, HIPC_MEM_BARRIER, and HIPC_queue::tail.