Difference between pages "r6:Function:slist delete all elements" and "r6:Function:slist delete element"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 4: Line 4:


==Prototype==
==Prototype==
  void slist_delete_all_elements( struct slist_state *ss );
  void slist_delete_element( struct slist_state *ss, struct slist_element *se );


==Parameters==
==Parameters==
''struct slist_state *ss''
''struct slist_state *ss''
: An slist state as allocated by ''[[r6:Function:slist_new|slist_new]]''.
: An slist state as allocated by ''[[r6:Function:slist_new|slist_new]]''.
''struct slist_element *se''
: A pointer to an slist element, as obtained from ''[[r6:Function:slist_new_head|slist_new_head]]'', ''[[r6:Function:slist_new_next|slist_new_next]]'', ''[[r6:Function:slist_get_head|slist_get_head]]'', ''[[r6:Function:slist_get_next|slist_get_next]]'' or ''[[r6:Function:slist_get_head_and_then_next|slist_get_head_and_then_next]]''.


==Return Value==
==Return Value==
Line 14: Line 17:


==Notes==
==Notes==
This function deletes every element in the slist.  This is not a logical delete - the elements are actually freed and the ''user_data_delete_function'' passed to ''slist_new'' is called with each user data void pointer immediately before the element is freedThis function is not thread-safe; it can only be issued by one thread and there can be no other in-progress slist operations when it is called.
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 ''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 ''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 ''slist_get_next'' to progress on to the next element in the slist.


==See Also==
==See Also==
* [[r6:API:SList|SList]]
* [[r6:API:SList|SList]]
* [[r6:Function:slist_delete|slist_delete]]
* [[r6:Function:slist_new_head|slist_new_head]]
* [[r6:Function:slist_new_next|slist_new_next]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/slist/slist_delete.c
/inc/liblfds.h

Prototype

void slist_delete_element( struct slist_state *ss, struct slist_element *se );

Parameters

struct slist_state *ss

An slist state as allocated by slist_new.

struct slist_element *se

A pointer to an slist element, as obtained from slist_new_head, slist_new_next, slist_get_head, slist_get_next or slist_get_head_and_then_next.

Return Value

No return value.

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 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 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 slist_get_next to progress on to the next element in the slist.

See Also