function lfds700_freelist_cleanup

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds700
    ├───inc
    │   └───liblfds700
    │           lfds700_freelist.h
    └───src
        └───lfds700_freelist
                lfds700_freelist_cleanup.c

Opaque Structures

struct lfds700_freelist_element;
struct lfds700_freelist_state;

Prototype

void lfds700_freelist_cleanup( struct lfds700_freelist_state *fs,
                               void (*element_cleanup_callback)(struct lfds700_freelist_state *fs, struct lfds700_freelist_element *fe) );

Parameters

struct lfds700_freelist_state *fs

A pointer to an initialized struct lfds700_freelist_state.

void (*element_cleanup_callback)(struct lfds700_freelist_state *fs, struct lfds700_freelist_element *fe)

A callback function which is called with every element present in the freelist 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 freelist elements valid for the current logical core and to iterate over the freelist and pass each element to the callback function.

The user can in the callback function use the LFDS700_FREELIST_GET_USER_STATE_FROM_STATE macro on the freelist state to get hold of the user state provided when the freelist was initialized.

Example

#include <stdio.h>
#include <string.h>
#include "liblfds700.h"
 
void element_cleanup_callback( struct lfds700_freelist_state *fs, struct lfds700_freelist_element *fe )
{
  char
    *name;

  affert( fs != NULL );
  affert( fe != NULL );

  name = LFDS700_FREELIST_GET_VALUE_FROM_ELEMENT( *fe );

  printf( "name = %s\n", name );

  free( name );

  return;
}
 
int main()
{
  char
    *name;

  struct lfds700_freelist_element
    fe;

  struct lfds700_freelist_state
    fs;

  struct lfds700_misc_prng_state
    ps;

  lfds700_misc_library_init_valid_on_current_logical_core();

  lfds700_misc_prng_init( &ps );

  lfds700_freelist_init_valid_on_current_logical_core( &fs, NULL );

  name = malloc( sizeof(char) * 64 );
  strcpy( name, "Queeg 500" );

  LFDS700_FREELIST_SET_VALUE_IN_ELEMENT( fe, name );
  lfds700_freelist_push( &fs, &fe, &ps );

  lfds700_freelist_cleanup( &fs, element_cleanup_callback );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also