r6.0.1:lfds601_ringbuffer_get_read_element

From liblfds.org
Jump to navigation Jump to search

Source Files

/liblfds601/src/lfds601_ringbuffer/lfds601_ringbuffer_get_and_put.c
/liblfds601/inc/liblfds601.h

Prototype

struct lfds601_freelist_element *lfds601_ringbuffer_get_read_element( struct lfds601_ringbuffer_state *rs, struct lfds601_freelist_element **fe );

Parameters

struct lfds601_ringbuffer_state *rs

A ringbuffer state as allocated by lfds601_ringbuffer_new.

struct lfds601_freelist_element **fe

A pointer to a pointer which will be set to point to the freelist element obtained from the ringbuffer. Set to NULL if there are no read elements.

Return Value

Returns a pointer to the current ringbuffer read element. Returns NULL if there are no read elements.

Notes

The ringbuffer uses freelist elements and as such when obtaining elements from the ringbuffer, freelist elements are obtained. As such, to get the user data in these elements, use the appropriate freelist function, lfds601_freelist_get_user_data_from_element.

To permit concurrent readers and writers, there must be a way to protect an element which is being read from being over-written while it is being read. The ringbuffer has no reference counting, so the solution adopted is for a thread performing a read to detach the current read element from the ringbuffer. This means that the element cannot be over-written while being read. It also means only one thread will read any one element, which may or may not be what you want, but it is what you've got :-)

See Also