r6.0.1:lfds601_ringbuffer_get_write_element

From liblfds.org
Revision as of 14:07, 4 January 2015 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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_current_write_element( struct lfds601_ringbuffer_state *rs, struct lfds601_freelist_element **fe, int *overwrite_flag );

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. This function never fails, so a NULL is never returned.

int *overwrite_flag

A pointer to an integer, where the integer is set to 1 if the function consumed a data bearing element from the ringbuffer or is set to 0 if the function was able to use an existing, available element. This argument can be NULL.

Return Value

Returns a pointer to the current ringbuffer write element. This function always succeeds.

Notes

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

To permit concurrent readers and writers, there must be a way to protect an element which is being written from being read before it is fully written. The solution adopted is for a thread performing a write to detach, if one is available, an unused element from the ringbuffer, or, if there are no unused elements, the current read element (thus leading to the over-writing of its contents).

See Also