#ifndef lib_circular_buffer_h #define lib_circular_buffer_h /* Cesar project {{{ * * Copyright (C) 2008 Spidcom * * <<>> * * }}} */ /** * \file lib/circular_buffer.h * \brief Circular buffer list * \ingroup lib * * Provides a circular buffer list API. * Reserve the real size of the buffer just after the declaration of the * circular buffer to not have some memory problems. */ struct circular_buffer_t { /** Number of slots of power of 2. */ uint num_slots; /** head. */ uint head; /** tail. */ uint tail; /** buffer. */ void **buffer; /** number of elements in the list. */ uint nb_elements; }; typedef struct circular_buffer_t circular_buffer_t; /** * Initialize the buffer address list * * \param list the buffer address list to initiliaze * \param buffer the circular buffer to use. * \param number_slots the quantity of slots. */ void circular_buffer_init (circular_buffer_t *list, void *buffer, uint number_slots); /** * Add an address to the buffer address buffer list * * \param ctx the ctx containing the list. * \param address the address to add to the list * \param number_of_slots the quantity of address it can keep in the list. * * \return true if the buffer had been added, false otherwise */ bool circular_buffer_add (circular_buffer_t *ctx, void *address); /** * Peek the first element of the list without removing it. * * \param ctx the context. */ void* circular_buffer_peek (circular_buffer_t *ctx); /** * Get the current address and go to the next one. * * \param ctx the ctx containing the list. * \param number_of_slots the quantity of address it can keep in the list. */ void* circular_buffer_get (circular_buffer_t *ctx); #endif /* lib_circular_buffer_h */