macro LFDS700_FREELIST_GET_KEY_FROM_ELEMENT
Source Files
└───liblfds700 └───inc └───liblfds700 lfds700_freelist.h
Opaque Structures
struct lfds700_freelist_element;
Macro
#define LFDS700_FREELIST_GET_KEY_FROM_ELEMENT( freelist_element )
Parameters
freelist_element
- A struct lfds700_freelist_element. Not a pointer to it - the struct itfelf.
Return Value
Returns a void pointer, the key from the element.
Notes
The key set into a freelist element is only guranteed to be visible to another logical core once the element has been popped by a thread running on that logical core.
So, for example, if there was a globally allocated freelist element, where a thread on logical core A set a value and then pushed the element to the freelist, a thread on logical core B would only be guaranteed to see the key set by the other thread once it pops the element from the freelist.
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 freelist, and is provided for convenience when moving keys and values between different data structures.
Example
#include <stdio.h> #include "liblfds700.h" int main() { char freelist_element_name[64] = "Tacitus", *freelist_element_name_temp; struct lfds700_misc_prng_state ps; struct lfds700_freelist_element fe, *fe_temp; struct lfds700_freelist_state fs; 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_KEY_IN_ELEMENT( &fe, (void *) freelist_element_name ); lfds700_freelist_push( &fs, &fe, &ps ); lfds700_freelist_pop( &fs, &fe_temp, &ps ); freelist_element_name_temp = (char *) LFDS700_FREELIST_GET_KEY_FROM_ELEMENT( *fs_temp ); printf( "freelist element name is \"%s\"\n", (char *) freelist_element_name_temp ); lfds700_freelist_cleanup( &fs, NULL ); lfds700_misc_library_cleanup(); return( EXIT_SUCCESS ); }