function lfds700_ringbuffer_init_valid_on_current_logical_core
Jump to navigation
Jump to search
Source Files
└───liblfds700 ├───inc │ └───liblfds700 │ lfds700_ringbuffer.h └───src └───lfds700_ringbuffer lfds700_ringbuffer_init.c
Opaque Structures
struct lfds700_misc_prng_state; struct lfds700_ringbuffer_state;
Prototype
void lfds700_ringbuffer_init_valid_on_current_logical_core( struct lfds700_ringbuffer_state *rs, struct lfds700_ringbuffer_element *re_array, lfds700_pal_uint_t number_elements, struct lfds700_misc_prng_state *ps, void *user_state );
Parameters
struct lfds700_ringbuffer_state *rs
- A pointer to a user-allocated struct lfds700_ringbuffer_state.
struct lfds700_ringbuffer_element *re_array
- A user-allocated array of LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES aligned struct lfds700_ringbuffer_element which are the store used by the ringbuffer. The number of elements in this array must be one more than the number of elements you wish to have in the ringbuffer, as the ringbuffer uses a dummy element. Stack declared variables will automatically be correctly aligned by the compiler, due to the information in the structure definitions; nothing has to be done. Heap allocated variables however will by no means be correctly aligned and an aligned malloc must be used.
lfds700_pal_uint_t number_elements
- The number of elements in the array pointed to by re_array. This is the actual real number of includes, i.e. including the dummy element.
struct lfds700_misc_prng_state *ps
- A pointer to an initialized struct lfds700_misc_prng_state.
void *user_state
- A pointer to void, supplied by the user, which is returned to the user in various callback functions, permitting the user to pass his own state into those functions. This argument can be NULL.
Notes
As the function name indicates, the initialization work performed on the ringbuffer state is only valid on the current logical core. To make this work valid on other logical cores, threads on other cores must call LFDS700_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE.
This function instantiates a ringbuffer by initializing the ringbuffer state. The caller is responsible for all memory allocation and, after lfds700_ringbuffer_cleanup is called, for all deallocation.
Example
#include "liblfds700.h" int main() { struct lfds700_misc_prng_state ps; struct lfds700_ringbuffer_element *re; struct lfds700_ringbuffer_state rs; lfds700_misc_library_init_valid_on_current_logical_core(); lfds700_misc_prng_init( &ps ); re = malloc( sizeof(struct lfds700_ringbuffer_element) * 11 ); // TRD : a ten element ringbuffer - the eleventh elements is the dummy element needed by the ringbuffer lfds700_ringbuffer_init_valid_on_current_logical_core( &rs, re, 11, &ps, NULL ); lfds700_ringbuffer_cleanup( rs, NULL ); free( re ); lfds700_misc_library_cleanup(); return( EXIT_SUCCESS ); }