Fix wrap bug in mtime_since()
[fio.git] / flist.h
diff --git a/flist.h b/flist.h
index f28a5ab7ef27250151cc1f1a5678b68fff519d5a..7aca9730b2e9621349cfb27b427c3ff19f91829f 100644 (file)
--- a/flist.h
+++ b/flist.h
@@ -1,6 +1,8 @@
 #ifndef _LINUX_FLIST_H
 #define _LINUX_FLIST_H
 
+#include <stdlib.h>
+
 #undef offsetof
 #ifdef __compiler_offsetof
 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
@@ -41,33 +43,34 @@ struct flist_head {
  * This is only for internal list manipulation where we know
  * the prev/next entries already!
  */
-static inline void __flist_add(struct flist_head *new,
+static inline void __flist_add(struct flist_head *new_entry,
                               struct flist_head *prev,
                               struct flist_head *next)
 {
-       next->prev = new;
-       new->next = next;
-       new->prev = prev;
-       prev->next = new;
+       next->prev = new_entry;
+       new_entry->next = next;
+       new_entry->prev = prev;
+       prev->next = new_entry;
 }
 
 /**
  * flist_add - add a new entry
- * @new: new entry to be added
+ * @new_entry: new entry to be added
  * @head: list head to add it after
  *
  * Insert a new entry after the specified head.
  * This is good for implementing stacks.
  */
-static inline void flist_add(struct flist_head *new, struct flist_head *head)
+static inline void flist_add(struct flist_head *new_entry,
+                             struct flist_head *head)
 {
-       __flist_add(new, head, head->next);
+       __flist_add(new_entry, head, head->next);
 }
 
-static inline void flist_add_tail(struct flist_head *new,
+static inline void flist_add_tail(struct flist_head *new_entry,
                                  struct flist_head *head)
 {
-       __flist_add(new, head->prev, head);
+       __flist_add(new_entry, head->prev, head);
 }
 
 /*
@@ -116,6 +119,36 @@ static inline int flist_empty(const struct flist_head *head)
        return head->next == head;
 }
 
+static inline void __flist_splice(const struct flist_head *list,
+                                 struct flist_head *prev,
+                                 struct flist_head *next)
+{
+       struct flist_head *first = list->next;
+       struct flist_head *last = list->prev;
+
+       first->prev = prev;
+       prev->next = first;
+
+       last->next = next;
+       next->prev = last;
+}
+
+static inline void flist_splice(const struct flist_head *list,
+                               struct flist_head *head)
+{
+       if (!flist_empty(list))
+               __flist_splice(list, head, head->next);
+}
+
+static inline void flist_splice_init(struct flist_head *list,
+                                   struct flist_head *head)
+{
+       if (!flist_empty(list)) {
+               __flist_splice(list, head, head->next);
+               INIT_FLIST_HEAD(list);
+       }
+}
+
 /**
  * flist_entry - get the struct for this entry
  * @ptr:       the &struct flist_head pointer.