Difference between pages "r6:Function:ringbuffer delete" and "r6:Function:ringbuffer get read element"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
==Source Files==
==Source Files==
  /src/ringbuffer/ringbuffer_delete.c
  /src/ringbuffer/ringbuffer_get_and_put.c
  /inc/liblfds.h
  /inc/liblfds.h


==Prototype==
==Prototype==
  void ringbuffer_delete( struct ringbuffer_state *rs,
  struct freelist_element *ringbuffer_get_read_element( struct ringbuffer_state *rs, struct freelist_element **fe );
                        void (*user_data_delete_function)(void *user_data, void *user_state),
                        void *user_state );


==Parameters==
==Parameters==
Line 12: Line 10:
: A ringbuffer state as allocated by ''[[r6:Function:ringbuffer_new|ringbuffer_new]]''.
: A ringbuffer state as allocated by ''[[r6:Function:ringbuffer_new|ringbuffer_new]]''.


''void (*user_data_delete_function)(void *user_data, void *user_state)''
''struct freelist_element **fe''
: A callback function, which can be NULL.  This function is called with the user data void pointer from each element before that element is deleted, giving the user an opportunity to delete any allocated state.
: 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.
 
''void *user_state''
: This pointer is passed into the ''user_data_delete_function'' as its second argument, enabling the caller to pass state into the callback function.


==Return Value==
==Return Value==
No return value.
Returns a pointer to the current ringbuffer read element.  Returns NULL if there are no read elements.


==Notes==
==Notes==
This function deletes the ringbuffer.  The user data void pointer in each element will be passed to ''user_data_delete_function'' prior to deletion, permitting the caller to release any per-element state.
The ringbuffer uses freelist elements and as such when obtaining elements from the ringbuffer, freelist elements are obtainedAs such, to get the user data in these elements, use the appropriate freelist function, ''[[r6:Function:freelist_get_user_data_from_element|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==
==See Also==
* [[r6:API:Ringbuffer|Ringbuffer]]
* [[r6:API:Ringbuffer|Ringbuffer]]
* [[r6:Function:ringbuffer_new|ringbuffer_new]]
* [[r6:Function:ringbuffer_put_read_element|ringbuffer_put_read_element]]
* [[r6:Function:freelist_get_user_data_from_element|freelist_get_user_data_from_element]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/ringbuffer/ringbuffer_get_and_put.c
/inc/liblfds.h

Prototype

struct freelist_element *ringbuffer_get_read_element( struct ringbuffer_state *rs, struct freelist_element **fe );

Parameters

struct ringbuffer_state *rs

A ringbuffer state as allocated by ringbuffer_new.

struct 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, 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