function lfds700_list_aos_init_valid_on_current_logical_core

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds700
    ├───inc
    │   └───liblfds700
    │           lfds700_list_addonly_ordered_singlylinked.h
    └───src
        └───llfds700_list_addonly_ordered_singlylinked
                lfds700_list_addonly_ordered_singlylinked_init.c

Enums

enum lfds700_list_aos_existing_key
{
  LFDS700_LIST_AOS_EXISTING_KEY_OVERWRITE,
  LFDS700_LIST_AOS_EXISTING_KEY_FAIL
};

Opaque Structures

struct lfds700_list_aos_state;

Prototype

void lfds700_list_aos_init( struct lfds700_list_aos_state *laoss,
                            int (*key_compare_function)(void const *new_key, void const *existing_key),
                            enum lfds700_list_aos_existing_key existing_key,
                            void *user_state );

Parameters

struct lfds700_list_aos_state *laoss

A pointer to a user-allocated LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES aligned struct lfds700_list_aos_state. Stack declared variables will automatically be correctly aligned by the compiler, due to the information in the structure definitions; nothing has to be done. Heap allocated variables however will by no means be correctly aligned and an aligned malloc must be used.

int (*key_compare_function)(void const *new_key, void const *existing_key)

A callback used by the list to compare keys. The callback returns 0 if the keys are equal, smaller than zero if new_key is smaller than existing_key and greater than zero if new_key is greater than existing_key (i.e. as strcmp).

enum lfds700_list_aos_existing_key existing_key

This argument specifies how the list should behave when attempting to add a key which already exists (see Notes).

void *user_state

A pointer to void, supplied by the user, which is returned to the user in various callback functions, permitting the user to pass his own state into those functions. This argument can be NULL.

Notes

As the function name indicates, the initialization work performed on the list state is only valid on the current logical core. To make this work valid on other logical cores, threads on other cores must call LFDS700_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE.

This function instantiates an add-only, ordered, singly-linked list by initializing the list state. The caller is responsible for all memory allocation and, after lfds700_list_aos_cleanup is called, for all deallocation.

The existing_key argument specifies how lfds700_list_aos_insert should behave when the attempt is made to add a new element which has a key which is already present in the btree.

If LFDS700_LIST_AOS_EXISTING_KEY_FAIL is specified, lfds700_list_aos_insert will fail, and return LFDS700_LIST_AOS_LINK_RESULT_FAILURE_EXISTING_KEY.

If LFDS700_LIST_AOS_EXISTING_KEY_OVERWRITE is specified, the attempt will cause the value in the new element to over-write that of the existing element, and lfds700_list_aos_insert will return LFDS700_LIST_AOS_LINK_RESULT_SUCCESS_OVERWRITE.

(In both cases, when a linking a key which is not present in the list, LFDS700_BTREE_AU_LINK_RESULT_SUCCESS is returned.)

Example

Coming soon. No, really! (Written 29th Dec 2015).

See Also