macro LFDS700_STACK_SET_KEY_IN_ELEMENT

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds700
    └───inc
        └───liblfds700
                lfds700_stack.h

Opaque Structures

struct lfds700_stack_element;

Macro

#define LFDS700_STACK_SET_KEY_IN_ELEMENT( stack_element, new_key )

Parameters

stack_element

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

new_key

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

Return Value

No return value.

Notes

The key in a stack element can only be set when the element is outside of a stack (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 stack, 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.

The key is not used in any way by the stack, and is provided for convenience when moving keys and values between different data structures.

Example

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

int main()
{
  char
    stack_element_name[64] = "Talky Toaster",
    *stack_element_name_temp;

  struct lfds700_misc_prng_state
    ps;

  struct lfds700_stack_element
    se,
    *se_temp;

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

  LFDS700_STACK_SET_KEY_IN_ELEMENT( &se, stack_element_name );

  lfds700_stack_push( &ss, &se, &ps );

  lfds700_stack_pop( &ss, &se_temp, &ps );

  stack_element_name_temp = (char *) LFDS700_STACK_GET_KEY_FROM_ELEMENT( *ss_temp );

  printf( "stack element name is \"%s\"\n", (char *) stack_element_name_temp );

  lfds700_stack_cleanup( &ss, NULL );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also