]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/slists.h
Merge branch 'master' into dev-sizet
[libucw.git] / ucw / slists.h
index bdab355d2a88842cf3c181f901f26ad0f133e624..1325c12376878974f74d682e599d396b6f792654 100644 (file)
 #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 */
@@ -155,9 +176,9 @@ static inline void slist_remove_tail(slist *l)
 /**
  * Compute the number of nodes in @l. Beware linear time complexity.
  **/
-static inline uns slist_size(slist *l)
+static inline uint slist_size(slist *l)
 {
-  uns i = 0;
+  uint i = 0;
   SLIST_FOR_EACH(snode *, n, *l)
     i++;
   return i;