]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.0.0/liblfds700/src/lfds700_ringbuffer/lfds700_ringbuffer_read.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.0.0 / liblfds700 / src / lfds700_ringbuffer / lfds700_ringbuffer_read.c
1 /***** includes *****/
2 #include "lfds700_ringbuffer_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 int lfds700_ringbuffer_read( struct lfds700_ringbuffer_state *rs,
10                              void **key,
11                              void **value,
12                              struct lfds700_misc_prng_state *ps )
13 {
14   int
15     rv;
16
17   struct lfds700_queue_element
18     *qe;
19
20   struct lfds700_ringbuffer_element
21     *re;
22
23   LFDS700_PAL_ASSERT( rs != NULL );
24   // TRD : key can be NULL
25   // TRD : value can be NULL
26   LFDS700_PAL_ASSERT( ps != NULL );
27
28   rv = lfds700_queue_dequeue( &rs->qs, &qe, ps );
29
30   if( rv == 1 )
31   {
32     re = LFDS700_QUEUE_GET_VALUE_FROM_ELEMENT( *qe );
33     re->qe_use = (struct lfds700_queue_element *) qe;
34     if( key != NULL )
35       *key = re->key;
36     if( value != NULL )
37       *value = re->value;
38     LFDS700_FREELIST_SET_VALUE_IN_ELEMENT( re->fe, re );
39     lfds700_freelist_push( &rs->fs, &re->fe, ps );
40   }
41
42   return( rv );
43 }
44