-/**
- *
- *
- * the size of this ring buffer
-*/
-unsigned size;
-/**
- *
- *
- * the actual entries of the ringbuffer
-*/
-void **entries;
-/**
- *
- *
- * the next entry will be added at this position
- */
-int head;
-/**
- *
- * how many entries the ring buffer contains
-*/
-unsigned filled;
+ /** The size of this ring buffer. */
+ unsigned size;
+ /** The actual entries of the ringbuffer. */
+ void **entries;
+ /** The next entry will be added at this position. */
+ int head;
+ /** How many entries the ring buffer contains. */
+ unsigned filled;
*
* This function initializes a circular ring buffer which can hold up to \a
* size entries of arbitrary type. If performance is an issue, \a size should
*
* This function initializes a circular ring buffer which can hold up to \a
* size entries of arbitrary type. If performance is an issue, \a size should
* many ringbuffers may be initialized via this function. Each ringbuffer is
* identified by a 'cookie'.
*
* many ringbuffers may be initialized via this function. Each ringbuffer is
* identified by a 'cookie'.
*
{
struct ringbuffer *rb = para_calloc(sizeof(struct ringbuffer));
rb->entries = para_calloc(size * sizeof(void *));
rb->size = size;
return rb;
{
struct ringbuffer *rb = para_calloc(sizeof(struct ringbuffer));
rb->entries = para_calloc(size * sizeof(void *));
rb->size = size;
return rb;
* the ringbuffer fills up, its oldest entry is disregarded and replaced by \a
* data.
*
* \return The old \a data pointer which is going to be disregarded, or
* NULL if the ringbuffer is not yet full.
*/
* the ringbuffer fills up, its oldest entry is disregarded and replaced by \a
* data.
*
* \return The old \a data pointer which is going to be disregarded, or
* NULL if the ringbuffer is not yet full.
*/
void *ret = rb->entries[rb->head];
rb->entries[rb->head] = data;
rb->head = (rb->head + 1) % rb->size;
void *ret = rb->entries[rb->head];
rb->entries[rb->head] = data;
rb->head = (rb->head + 1) % rb->size;
*
* \return A pointer to data previously added, or NULL if entry number
* \a num is not available. \a num counts backwards from zero, i.e.
* ringbuffer_get_entry(0) gets the entry which was added most recently.
*/
*
* \return A pointer to data previously added, or NULL if entry number
* \a num is not available. \a num counts backwards from zero, i.e.
* ringbuffer_get_entry(0) gets the entry which was added most recently.
*/
int pos = (rb->head + rb->size - 1 - num) % rb->size;
// fprintf(stderr, "pos = %d\n", pos);
return rb->entries[pos];
}
/**
int pos = (rb->head + rb->size - 1 - num) % rb->size;
// fprintf(stderr, "pos = %d\n", pos);
return rb->entries[pos];
}
/**