Contiki-NG
Macros | Typedefs | Functions

This library provides functions for the creation and manipulation of queues. More...

Macros

#define QUEUE(name)   LIST(name)
 Define a queue. More...
 

Typedefs

typedef list_t queue_t
 The queue data type.
 

Functions

static void queue_init (queue_t queue)
 Initialise a queue. More...
 
static void queue_enqueue (queue_t queue, void *element)
 Adds an element to the tail of the queue. More...
 
static void * queue_dequeue (queue_t queue)
 Removes the element at the front of the queue. More...
 
static void * queue_peek (queue_t queue)
 Returns the front element of the queue, without removing it. More...
 
static bool queue_is_empty (queue_t queue)
 Check if a queue is empty. More...
 

Detailed Description

This library provides functions for the creation and manipulation of queues.

The library is implemented as a wrapper around the list library.

A queue is declared using the QUEUE macro. Queue elements must be allocated by the calling code and must be of a C struct datatype. In this struct, the first field must be a pointer called next. This field will be used by the library to maintain the queue. Application code must not modify this field directly.

This library is not safe to be used within an interrupt context.

Macro Definition Documentation

◆ QUEUE

#define QUEUE (   name)    LIST(name)

Define a queue.

This macro defines a queue.

The datatype for elements must be a C struct. The struct's first member must be a pointer called next. This is used internally by the library to maintain data structure integrity and must not be modified directly by application code.

Parameters
nameThe name of the queue.

Definition at line 77 of file queue.h.

Function Documentation

◆ queue_dequeue()

static void* queue_dequeue ( queue_t  queue)
inlinestatic

Removes the element at the front of the queue.

Parameters
queueThe queue
Returns
A pointer to the element removed

If this function returns NULL if the queue was empty (queue underflow)

Definition at line 112 of file queue.h.

References list_pop().

◆ queue_enqueue()

static void queue_enqueue ( queue_t  queue,
void *  element 
)
inlinestatic

Adds an element to the tail of the queue.

Parameters
queueThe queue
elementA pointer to the element to be added

Definition at line 99 of file queue.h.

References list_add().

◆ queue_init()

static void queue_init ( queue_t  queue)
inlinestatic

Initialise a queue.

Parameters
queueThe queue

Definition at line 88 of file queue.h.

References list_init().

◆ queue_is_empty()

static bool queue_is_empty ( queue_t  queue)
inlinestatic

Check if a queue is empty.

Parameters
queueThe queue
Return values
trueThe queue is empty
falseThe queue has at least one element

Definition at line 135 of file queue.h.

◆ queue_peek()

static void* queue_peek ( queue_t  queue)
inlinestatic

Returns the front element of the queue, without removing it.

Parameters
queueThe queue
Returns
A pointer to the element at the front of the queue

Definition at line 123 of file queue.h.

References list_head().