r6.1.1:lfds611_slist_logically_delete_element

From liblfds.org
Revision as of 14:07, 4 January 2015 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source Files

/liblfds611/src/lfds611_slist/lfds611_slist_delete.c
/liblfds611/inc/liblfds611.h

Prototype

int lfds611_slist_logically_delete_element( struct lfds611_slist_state *ss, struct lfds611_slist_element *se );

Parameters

struct lfds611_slist_state *ss

An slist state as allocated by lfds611_slist_new.

struct lfds611_slist_element *se

A pointer to an slist element, as obtained from lfds611_slist_new_head, lfds611_slist_new_next, lfds611_slist_get_head, lfds611_slist_get_next or lfds611_slist_get_head_and_then_next.

Return Value

Returns 1 if the call deleted the element, 0 if the element was already deleted.

Notes

This function logically deletes se. By logically delete, it is meant that the memory for the slist element is not freed and the element remains in the list (thus continuing to affect traversal performance) but that the element is no longer apparent to the user of the list; for example, calling lfds611_slist_get_next on the element immediately before a deleted element will return the element immediately after the deleted element.

It may be that other threads still hold a pointer to the logically deleted element. The element however is still in the list and all operations on the list properly update the pointers in deleted elements, so it is safe to perform all slist operations on a deleted element so you can also for example call lfds611_slist_new_next on a deleted element and insert a new element after the deleted element.

As such, it is expected and normal after an element has been deleted to call lfds611_slist_get_next to progress on to the next element in the slist.

See Also