X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fslists.h;h=961748f30f86332ca024c5c6a67969dc9b7982bc;hb=0db6e10eac28f38bfc3b325b13ad95107c58ce1e;hp=bdab355d2a88842cf3c181f901f26ad0f133e624;hpb=709279f8819aa12bf6daa83bf3f47588c193964b;p=libucw.git diff --git a/ucw/slists.h b/ucw/slists.h index bdab355d..961748f3 100644 --- a/ucw/slists.h +++ b/ucw/slists.h @@ -10,6 +10,12 @@ #ifndef _UCW_SLISTS_H #define _UCW_SLISTS_H +#ifdef CONFIG_UCW_CLEAN_ABI +#define slist_insert_before ucw_slist_insert_before +#define slist_prev ucw_slist_prev +#define slist_remove ucw_slist_remove +#endif + /** * Common header for list nodes. **/ @@ -116,15 +122,30 @@ static inline void slist_remove_after(slist *l, snode *after) /** * Remove the first node in @l. The list can be empty. **/ -static inline void slist_remove_head(slist *l) +static inline void *slist_remove_head(slist *l) { - slist_remove_after(l, &l->head); + snode *n = slist_head(l); + if (n) + slist_remove_after(l, &l->head); + return n; } /* Loops */ +/** + * Loop over all nodes in the @list and perform the next C statement on them. The current node is stored in @n which must be defined before as pointer to any type. + * The list should not be changed during this loop command. + **/ #define SLIST_WALK(n,list) for(n=(void*)(list).head.next; (n); (n)=(void*)((snode*)(n))->next) + +/** + * Same as @SLIST_WALK(), but allows removal of the current node. This macro requires one more variable to store the pointer to the previous node (useful for @slist_remove_after()). + **/ #define SLIST_WALK_DELSAFE(n,list,prev) for((prev)=(void*)&(list).head; (n)=(void*)((snode*)prev)->next; (prev)=(((snode*)(prev))->next==(snode*)(n) ? (void*)(n) : (void*)(prev))) + +/** + * Same as @SLIST_WALK(), but it defines the variable for the current node in place. @type should be a pointer type. + **/ #define SLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; n; n=(void*)((snode*)(n))->next) /* Non-trivial functions */