function lfds700_freelist_push

From liblfds.org
Jump to navigation Jump to search

Source Files

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

Opaque Structures

struct lfds700_freelist_element;
struct lfds700_freelist_state;
struct lfds700_misc_prng_state;

Prototype

void lfds700_freelist_push( struct lfds700_freelist_state *fs,
                            struct lfds700_freelist_element *fe,
                            struct lfds700_misc_prng_state *ps );

Parameters

struct lfds700_freelist_state *fs

A pointer to an initialized struct lfds700_freelist_state.

struct lfds700_freelist_element *fe

A pointer to a user-allocated struct lfds700_freelist_element. There are no alignement requirements for this structure.

struct lfds700_misc_prng_state *ps

A pointer to an initialized struct lfds700_misc_prng_state.

Notes

This function pushes a freelist element, with its key and value, onto the freelist. The key and value are both optional, are set by the macros LFDS700_FREELIST_SET_KEY_IN_ELEMENT and LFDS700_FREELIST_SET_VALUE_IN_ELEMENT respectively, and can only be set when a freelist element is outside of a freelist.

The third argument, the struct lfds700_misc_prng_state, is the state for a single-threaded, fast, high quality random number generator, required by the exponential backoff code. Each thread should allocate and initialize one of these structures, and then it can be used for all API calls which take this argument.

Example

#include "liblfds700.h"

int main()
{
  char
    name[64] = "Bob the Skutter";

  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 );

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

  lfds700_freelist_cleanup( &fs, NULL );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also