]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.0.0/liblfds700/src/lfds700_ringbuffer/lfds700_ringbuffer_init.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.0.0 / liblfds700 / src / lfds700_ringbuffer / lfds700_ringbuffer_init.c
1 /***** includes *****/
2 #include "lfds700_ringbuffer_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 void lfds700_ringbuffer_init_valid_on_current_logical_core( struct lfds700_ringbuffer_state *rs,
10                                                             struct lfds700_ringbuffer_element *re_array_inc_dummy,
11                                                             lfds700_pal_uint_t number_elements,
12                                                             struct lfds700_misc_prng_state *ps,
13                                                             void *user_state )
14 {
15   lfds700_pal_uint_t
16     loop;
17
18   LFDS700_PAL_ASSERT( rs != NULL );
19   LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &rs->fs % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
20   LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &rs->qs % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
21   LFDS700_PAL_ASSERT( re_array_inc_dummy != NULL );
22   LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &re_array_inc_dummy[0].fe % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
23   LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &re_array_inc_dummy[0].qe % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
24   LFDS700_PAL_ASSERT( number_elements >= 2 );
25   LFDS700_PAL_ASSERT( ps != NULL );
26   // TRD : user_state can be NULL
27
28   rs->user_state = user_state;
29
30   re_array_inc_dummy[0].qe_use = &re_array_inc_dummy[0].qe;
31
32   lfds700_freelist_init_valid_on_current_logical_core( &rs->fs, rs );
33   lfds700_queue_init_valid_on_current_logical_core( &rs->qs, &re_array_inc_dummy[0].qe, ps, rs );
34
35   for( loop = 1 ; loop < number_elements ; loop++ )
36   {
37     LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &re_array_inc_dummy[loop].fe % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
38     LFDS700_PAL_ASSERT( (lfds700_pal_uint_t) &re_array_inc_dummy[loop].qe % LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES == 0 );
39
40     re_array_inc_dummy[loop].qe_use = &re_array_inc_dummy[loop].qe;
41     LFDS700_FREELIST_SET_VALUE_IN_ELEMENT( re_array_inc_dummy[loop].fe, &re_array_inc_dummy[loop] );
42     lfds700_freelist_push( &rs->fs, &re_array_inc_dummy[loop].fe, ps );
43   }
44
45   LFDS700_MISC_BARRIER_STORE;
46
47   lfds700_misc_force_store();
48
49   return;
50 }
51