.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "" "" "2023-05-31" "PMDK - " "PMDK Programmer's Manual" .hy .\" SPDX-License-Identifier: BSD-3-Clause .\" Copyright 2017-2018, Intel Corporation .SH NAME .PP \f[B]pmemobj_list_insert\f[R](), \f[B]pmemobj_list_insert_new\f[R](), \f[B]pmemobj_list_move\f[R](), \f[B]pmemobj_list_remove\f[R]() - non-transactional persistent atomic lists functions .SH SYNOPSIS .IP .nf \f[C] #include int pmemobj_list_insert(PMEMobjpool *pop, size_t pe_offset, void *head, PMEMoid dest, int before, PMEMoid oid); PMEMoid pmemobj_list_insert_new(PMEMobjpool *pop, size_t pe_offset, void *head, PMEMoid dest, int before, size_t size, uint64_t type_num, pmemobj_constr constructor, void arg); int pmemobj_list_move(PMEMobjpool *pop, size_t pe_old_offset, void *head_old, size_t pe_new_offset, void *head_new, PMEMoid dest, int before, PMEMoid oid); int pmemobj_list_remove(PMEMobjpool *pop, size_t pe_offset, void *head, PMEMoid oid, int free); \f[R] .fi .SH DESCRIPTION .PP In addition to the container operations on internal object collections described in \f[B]pmemobj_first\f[R](3), \f[B]libpmemobj\f[R](7) provides a mechanism for organizing persistent objects in user-defined, persistent, atomic, circular, doubly-linked lists. All the routines and macros operating on the persistent lists provide atomicity with respect to any power-fail interruptions. If any of those operations is torn by program failure or system crash, on recovery they are guaranteed to be entirely completed or discarded, leaving the lists, persistent memory heap and internal object containers in a consistent state. .PP The persistent atomic circular doubly linked lists support the following functionality: .IP \[bu] 2 Insertion of an object at the head of the list, or at the end of the list. .IP \[bu] 2 Insertion of an object before or after any element in the list. .IP \[bu] 2 Atomic allocation and insertion of a new object at the head of the list, or at the end of the list. .IP \[bu] 2 Atomic allocation and insertion of a new object before or after any element in the list. .IP \[bu] 2 Atomic moving of an element from one list to the specific location on another list. .IP \[bu] 2 Removal of any object in the list. .IP \[bu] 2 Atomic removal and freeing of any object in the list. .IP \[bu] 2 Forward or backward traversal through the list. .PP A list is headed by a \f[I]list_head\f[R] structure containing the object handle of the first element on the list. The elements are doubly linked so that an arbitrary element can be removed without the need to traverse the list. New elements can be added to the list before or after an existing element, at the head of the list, or at the tail of the list. A list may be traversed in either direction. .PP The user-defined structure of each element must contain a field of type \f[I]list_entry\f[R] that holds the object handles to the previous and next element on the list. Both the \f[I]list_head\f[R] and the \f[I]list_entry\f[R] structures are declared in \f[B]\f[R]. .PP The functions below are intended to be used outside transactions - transactional variants are described in manpages to functions mentioned at \f[B]TRANSACTIONAL OBJECT MANIPULATION\f[R] in \f[B]libpmemobj\f[R](7). Note that operations performed using this non-transactional API are independent from their transactional counterparts. If any non-transactional allocations or list manipulations are performed within an open transaction, the changes will not be rolled back if such a transaction is aborted or interrupted. .PP The list insertion and move functions use a common set of arguments to define where an object will be inserted into the list. \f[I]dest\f[R] identifies the element before or after which the object will be inserted, or, if \f[I]dest\f[R] is \f[B]OID_NULL\f[R], indicates that the object should be inserted at the head or tail of the list. \f[I]before\f[R] determines where the object will be inserted: .IP \[bu] 2 \f[B]POBJ_LIST_DEST_BEFORE\f[R] - insert the element before the existing element \f[I]dest\f[R] .IP \[bu] 2 \f[B]POBJ_LIST_DEST_AFTER\f[R] - insert the element after the existing element \f[I]dest\f[R] .IP \[bu] 2 \f[B]POBJ_LIST_DEST_HEAD\f[R] - when \f[I]dest\f[R] is \f[B]OID_NULL\f[R], insert the element at the head of the list .IP \[bu] 2 \f[B]POBJ_LIST_DEST_TAIL\f[R] - when \f[I]dest\f[R] is \f[B]OID_NULL\f[R], insert the element at the tail of the list .RS .PP NOTE: Earlier versions of \f[B]libpmemobj\f[R](7) do not define \f[B]POBJ_LIST_DEST_BEFORE\f[R] and \f[B]POBJ_LIST_DEST_AFTER\f[R]. Use 1 for before, and 0 for after. .RE .PP The \f[B]pmemobj_list_insert\f[R]() function inserts the element represented by object handle \f[I]oid\f[R] into the list referenced by \f[I]head\f[R], at the location specified by \f[I]dest\f[R] and \f[I]before\f[R] as described above. \f[I]pe_offset\f[R] specifies the offset of the structure that connects the elements in the list. All the handles \f[I]head\f[R], \f[I]dest\f[R] and \f[I]oid\f[R] must point to objects allocated from memory pool \f[I]pop\f[R]. \f[I]head\f[R] and \f[I]oid\f[R] cannot be \f[B]OID_NULL\f[R]. .PP The \f[B]pmemobj_list_insert_new\f[R]() function atomically allocates a new object of given \f[I]size\f[R] and type \f[I]type_num\f[R] and inserts it into the list referenced by \f[I]head\f[R] at the location specified by \f[I]dest\f[R] and \f[I]before\f[R] as described above. \f[I]pe_offset\f[R] specifies the offset of the structure that connects the elements in the list. The handles \f[I]head\f[R] and \f[I]dest\f[R] must point to objects allocated from memory pool \f[I]pop\f[R]. Before returning, \f[B]pmemobj_list_insert_new\f[R]() calls the \f[I]constructor\f[R] function, passing the pool handle \f[I]pop\f[R], the pointer to the newly allocated object \f[I]ptr\f[R], and the \f[I]arg\f[R] argument. It is guaranteed that the allocated object is either properly initialized or, if the allocation is interrupted before the constructor completes, the memory space reserved for the object is reclaimed. \f[I]head\f[R] cannot be \f[B]OID_NULL\f[R]. The allocated object is also added to the internal container associated with \f[I]type_num\f[R], as described in \f[B]POBJ_FOREACH\f[R](3). .PP The \f[B]pmemobj_list_move\f[R]() function moves the object represented by object handle \f[I]oid\f[R] from the list referenced by \f[I]head_old\f[R] to the list referenced by \f[I]head_new\f[R], inserting it at the location specified by \f[I]dest\f[R] and \f[I]before\f[R] as described above. \f[I]pe_old_offset\f[R] and \f[I]pe_new_offset\f[R] specify the offsets of the structures that connect the elements in the old and new lists, respectively. All the handles \f[I]head_old\f[R], \f[I]head_new\f[R], \f[I]dest\f[R] and \f[I]oid\f[R] must point to objects allocated from memory pool \f[I]pop\f[R]. \f[I]head_old\f[R], \f[I]head_new\f[R] and \f[I]oid\f[R] cannot be \f[B]OID_NULL\f[R]. .PP The \f[B]pmemobj_list_remove\f[R]() function removes the object represented by object handle \f[I]oid\f[R] from the list referenced by \f[I]head\f[R]. If \f[I]free\f[R] is set, it also removes the object from the internal object container and frees the associated memory space. \f[I]pe_offset\f[R] specifies the offset of the structure that connects the elements in the list. Both \f[I]head\f[R] and \f[I]oid\f[R] must point to objects allocated from memory pool \f[I]pop\f[R] and cannot be \f[B]OID_NULL\f[R]. .SH RETURN VALUE .PP On success, \f[B]pmemobj_list_insert\f[R](), \f[B]pmemobj_list_remove\f[R]() and \f[B]pmemobj_list_move\f[R]() return 0. On error, they return -1 and set \f[I]errno\f[R] appropriately. .PP On success, \f[B]pmemobj_list_insert_new\f[R]() returns a handle to the newly allocated object. If the constructor returns a non-zero value, the allocation is canceled, -1 is returned, and \f[I]errno\f[R] is set to \f[B]ECANCELED\f[R]. On other errors, \f[B]OID_NULL\f[R] is returned and \f[I]errno\f[R] is set appropriately. .SH SEE ALSO .PP \f[B]pmemobj_first\f[R](3), \f[B]POBJ_FOREACH\f[R](3), \f[B]libpmemobj\f[R](7) and \f[B]\f[R]