utils
utilities in C for microcontrollers
Data Structures | Macros | Functions
queue.h File Reference

A generic FIFO queue. More...

#include <stdlib.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  queue_NAME
 instance type generated by QUEUE with name set to NAME, type set to TYPE, and size set to SIZE More...
 

Macros

#define QUEUE(name, type, size)
 Generates the queue api. More...
 

Functions

static int queue_NAME_init (volatile struct queue_NAME *self)
 init function generated by QUEUE with name set to NAME, type set to TYPE, and size set to SIZE More...
 
static int queue_NAME_push (volatile struct queue_NAME *self, const volatile TYPE *item)
 push an item onto the queue More...
 
static int queue_NAME_pop (volatile struct queue_NAME *self, volatile TYPE *item)
 pop an item from the queue More...
 
static size_t queue_NAME_count (const volatile struct queue_NAME *self)
 get the number of items in the queue More...
 
static void queue_NAME_foreach (volatile struct queue_NAME *self, int(*fun)(volatile TYPE *, volatile void *), volatile void *ctx)
 calls fun for each item in the queue More...
 

Detailed Description

A generic FIFO queue.

Macro Definition Documentation

◆ QUEUE

#define QUEUE (   name,
  type,
  size 
)

Generates the queue api.

Parameters
namea name for the api with the given type and size
typethe type of data to store in the queue
sizethe max number of data elements

Function Documentation

◆ queue_NAME_count()

size_t queue_NAME_count ( const volatile struct queue_NAME self)
inlinestatic

get the number of items in the queue

Parameters
selfthe queue_NAME from which to get the item count
Returns
the item count

◆ queue_NAME_foreach()

void queue_NAME_foreach ( volatile struct queue_NAME self,
int(*)(volatile TYPE *, volatile void *)  fun,
volatile void *  ctx 
)
inlinestatic

calls fun for each item in the queue

Parameters
selfthe queue to traverse
funa function pointer that takes a pointer to TYPE and a pointer to void
if fun returns 0 then the traversal will continue otherwise it will stop
ctxa pointer to arbitrary context that gets passed as the second argument to fun for each item in the queue

◆ queue_NAME_init()

int queue_NAME_init ( volatile struct queue_NAME self)
inlinestatic

init function generated by QUEUE with name set to NAME, type set to TYPE, and size set to SIZE

Parameters
selfthe queue_NAME to initialize
Returns
0 if successful

◆ queue_NAME_pop()

int queue_NAME_pop ( volatile struct queue_NAME self,
volatile TYPE *  item 
)
inlinestatic

pop an item from the queue

Parameters
selfthe queue_NAME from which to pop the item
itempointer the location to which the item should be copied
Returns
0 if successful

◆ queue_NAME_push()

int queue_NAME_push ( volatile struct queue_NAME self,
const volatile TYPE *  item 
)
inlinestatic

push an item onto the queue

Parameters
selfthe queue_NAME on which to push the item
itempointer to the item to push
Returns
0 if successful