1 #include "lfds600_ringbuffer_internal.h"
7 /****************************************************************************/
8 struct lfds600_freelist_element *lfds600_ringbuffer_get_read_element( struct lfds600_ringbuffer_state *rs, struct lfds600_freelist_element **fe )
13 lfds600_queue_dequeue( rs->qs, (void **) fe );
22 /****************************************************************************/
23 struct lfds600_freelist_element *lfds600_ringbuffer_get_write_element( struct lfds600_ringbuffer_state *rs, struct lfds600_freelist_element **fe, int *overwrite_flag )
27 // TRD : overwrite_flag can be NULL
29 /* TRD : we try to obtain an element from the lfds600_freelist
30 if we can, we populate it and add it to the lfds600_queue
32 if we cannot, then the lfds600_ringbuffer is full
33 so instead we grab the current read element and
36 dequeue may fail since the lfds600_queue may be emptied
37 during our dequeue attempt
39 so what we actually do here is a loop, attempting
40 the lfds600_freelist and if it fails then a dequeue, until
43 once we have an element, we lfds600_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 lfds600_freelist
50 is empty; but by the time we go to get an element from
51 the lfds600_queue, the whole lfds600_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 lfds600_freelist, 1 if we
56 stole an element from the lfds600_queue
61 if( overwrite_flag != NULL )
64 lfds600_freelist_pop( rs->fs, fe );
68 lfds600_ringbuffer_get_read_element( rs, fe );
70 if( overwrite_flag != NULL and *fe != NULL )
83 /****************************************************************************/
84 void lfds600_ringbuffer_put_read_element( struct lfds600_ringbuffer_state *rs, struct lfds600_freelist_element *fe )
89 lfds600_freelist_push( rs->fs, fe );
98 /****************************************************************************/
99 void lfds600_ringbuffer_put_write_element( struct lfds600_ringbuffer_state *rs, struct lfds600_freelist_element *fe )
101 assert( rs != NULL );
102 assert( fe != NULL );
104 lfds600_queue_enqueue( rs->qs, fe );