1 #include "lfds610_ringbuffer_internal.h"
7 /****************************************************************************/
8 struct lfds610_freelist_element *lfds610_ringbuffer_get_read_element( struct lfds610_ringbuffer_state *rs, struct lfds610_freelist_element **fe )
13 lfds610_queue_dequeue( rs->qs, (void **) fe );
22 /****************************************************************************/
23 struct lfds610_freelist_element *lfds610_ringbuffer_get_write_element( struct lfds610_ringbuffer_state *rs, struct lfds610_freelist_element **fe, int *overwrite_flag )
27 // TRD : overwrite_flag can be NULL
29 /* TRD : we try to obtain an element from the lfds610_freelist
30 if we can, we populate it and add it to the lfds610_queue
32 if we cannot, then the lfds610_ringbuffer is full
33 so instead we grab the current read element and
36 dequeue may fail since the lfds610_queue may be emptied
37 during our dequeue attempt
39 so what we actually do here is a loop, attempting
40 the lfds610_freelist and if it fails then a dequeue, until
43 once we have an element, we lfds610_queue it
45 you may be wondering why this operation is in a loop
46 remember - these operations are lock-free; anything
49 so for example the pop could fail because the lfds610_freelist
50 is empty; but by the time we go to get an element from
51 the lfds610_queue, the whole lfds610_queue has been emptied back into
54 if overwrite_flag is provided, we set it to 0 if we
55 obtained a new element from the lfds610_freelist, 1 if we
56 stole an element from the lfds610_queue
61 if( overwrite_flag != NULL )
64 lfds610_freelist_pop( rs->fs, fe );
68 lfds610_ringbuffer_get_read_element( rs, fe );
70 if( overwrite_flag != NULL and *fe != NULL )
83 /****************************************************************************/
84 void lfds610_ringbuffer_put_read_element( struct lfds610_ringbuffer_state *rs, struct lfds610_freelist_element *fe )
89 lfds610_freelist_push( rs->fs, fe );
98 /****************************************************************************/
99 void lfds610_ringbuffer_put_write_element( struct lfds610_ringbuffer_state *rs, struct lfds610_freelist_element *fe )
101 assert( rs != NULL );
102 assert( fe != NULL );
104 lfds610_queue_enqueue( rs->qs, fe );