function lfds710_btree_au_init_valid_on_current_logical_core

Revision as of 17:26, 30 May 2016 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source Files

    │   └───liblfds710
    │           lfds710_lfds710_btree_addonly_unbalanced.h

Opaque Structures

struct lfds710_btree_au_state;


enum lfds710_btree_au_existing_key


void lfds710_btree_au_init_valid_on_current_logical_core( struct lfds710_btree_au_state *baus,
                                                          int (*key_compare_function)(void const *new_key, void const *existing_key),
                                                          enum lfds710_btree_au_existing_key existing_key,
                                                          void *user_state );


struct lfds710_btree_au_state *baus

A pointer to a user-allocated LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES aligned struct lfds710_btree_au_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 btree to compare keys. Idential to the qsort callback, and is compatible with strcmp. 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.

enum lfds710_btree_au_existing_key existing_key

This argument specifies how the btree 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 callback functions, permitting the user to pass his own state into those functions. This argument can be NULL.


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

This function instantiates a btree by initializing the btree state. The caller is responsible for all memory allocation and, after lfds710_btree_au_cleanup is called, for all deallocation.

The existing_key argument specifies how lfds710_btree_au_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 LFDS710_BTREE_AU_EXISTING_KEY_FAIL is specified, lfds710_btree_au_insert will fail, and return LFDS710_BTREE_AU_LINK_RESULT_FAILURE_EXISTING_KEY.

If LFDS710_BTREE_AU_EXISTING_KEY_OVERWRITE is specified, the attempt will cause the value in the new element to over-write that of the existing element, and lfds710_btree_au_insert will return LFDS710_BTREE_AU_LINK_RESULT_SUCCESS_OVERWRITE.

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

See Also