function lfds700_stack_cleanup
Jump to navigation
Jump to search
Source Files
└───liblfds700 ├───inc │ └───liblfds700 │ lfds700_stack.h └───src └───lfds700_stack lfds700_stack_cleanup.c
Opaque Structures
struct lfds700_stack_element; struct lfds700_stack_state;
Prototype
void lfds700_stack_cleanup( struct lfds700_stack_state *ss, void (*element_cleanup_callback)(struct lfds700_stack_state *ss, struct lfds700_stack_element *se) );
Parameters
struct lfds700_stack_state *ss
- A pointer to an initialized struct lfds700_stack_state.
void (*element_cleanup_callback)(struct lfds700_stack_state *ss, struct lfds700_stack_element *se)
- A callback function which is called with every element present in the stack at the time of cleanup. This argument can be NULL.
Notes
The cleanup function actually does no work except, if the callback function is provided, to make all pushed stack elements valid for the current logical core and to iterate over the stack and pass each element to the callback function.
The user can in the callback function use the LFDS700_STACK_GET_USER_STATE_FROM_STATE macro on the stack state to get hold of the user state provided when the stack was initialized.
Example
#include <stdio.h> #include <string.h> #include "liblfds700.h" void element_cleanup_callback( struct lfds700_stack_state *ss, struct lfds700_stack_element *se ) { char *name; assert( ss != NULL ); assert( se != NULL ); name = LFDS700_STACK_GET_VALUE_FROM_ELEMENT( *se ); printf( "name = %s\n", name ); free( name ); return; } int main() { char *name; struct lfds700_misc_prng_state ps; struct lfds700_stack_element se; struct lfds700_stack_state ss; lfds700_misc_library_init_valid_on_current_logical_core(); lfds700_misc_prng_init( &ps ); lfds700_stack_init_valid_on_current_logical_core( &ss, NULL ); name = malloc( sizeof(char) * 64 ); strcpy( name, "Queeg 500" ); LFDS700_STACK_SET_VALUE_IN_ELEMENT( se, name ); lfds700_stack_push( &ss, &se, &ps ); lfds700_stack_cleanup( &ss, element_cleanup_callback ); lfds700_misc_library_cleanup(); return( EXIT_SUCCESS ); }