macro LFDS711_FREELIST_SET_VALUE_IN_ELEMENT

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds711
    └───inc
        └───liblfds711
                lfds711_freelist.h

Opaque Structures

struct lfds711_freelist_element;

Macro

#define LFDS711_FREELIST_SET_VALUE_IN_ELEMENT( freelist_element, new_value )

Parameters

freelist_element

A struct lfds711_freelist_element, which is not currently part of a freelist. Not a pointer to it - the struct itself.

new_value

A pointer, which will be cast by the macro to a void *, which the value in freelist_element is set to.

Return Value

No return value.

Notes

The value in a freelist element can only be set when the element is outside of a freelist (i.e. has been popped, or has yet to be pushed). This macro can be called at any time, but if it is used on an element which is present in a freelist, all bets are off - all threads on the logical core which does this will see the change, but there is no guarantee any other logical cores will ever see the change. You were warned.

As with all liblfds macros, the macro operates on the structure itself, not a pointer to it.

Example

#include <stdio.h>
#include "liblfds711.h"

int main()
{
  char
    freelist_element_name[64] = "Polybius",
    *freelist_element_name_temp;

  struct lfds711_misc_prng_state
    ps;

  struct lfds711_freelist_element
    fe,
    *fe_temp;

  struct lfds711_freelist_state
    fs;

  lfds711_misc_library_init_valid_on_current_logical_core();
 
  lfds711_misc_prng_init( &ps );

  lfds711_freelist_init_valid_on_current_logical_core( &fs, NULL );

  LFDS711_FREELIST_SET_VALUE_IN_ELEMENT( &fe, freelist_element_name );

  lfds711_freelist_push( &fs, &fe, &ps );

  lfds711_freelist_pop( &fs, &fe_temp, &ps );

  freelist_element_name_temp = (char *) LFDS711_FREELIST_GET_VALUE_FROM_ELEMENT( *fs_temp );

  printf( "freelist element name is \"%s\"\n", (char *) freelist_element_name_temp );

  lfds711_freelist_cleanup( &fs, NULL );

  lfds711_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also