Added list_splice to btt/list.h
authorAlan D. Brunelle <Alan.Brunelle@hp.com>
Tue, 2 Oct 2007 16:08:34 +0000 (12:08 -0400)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 2 Oct 2007 17:50:58 +0000 (19:50 +0200)
list_splice is needed for the addition of btrecord/btreplay.

Signed-off-by: Alan D. Brunelle <Alan.Brunelle@hp.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
btt/list.h

index f28f0fb2050bd831efd6268e49c588258348ea5d..363c888727ce17227f3b21c67a2654e5c592d731 100644 (file)
@@ -1,6 +1,28 @@
 #ifndef _LINUX_LIST_H
 #define _LINUX_LIST_H
 
+#include <stdio.h>
+
+#ifndef offsetof
+/**
+ * Get offset of a member
+ */
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#ifndef container_of
+/**
+ * Casts a member of a structure out to the containing structure
+ * @param ptr        the pointer to the member.
+ * @param type       the type of the container struct this is embedded in.
+ * @param member     the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+               (type *)( (char *)__mptr - offsetof(type,member) );})
+#endif
+
 /*
  * These are non-NULL pointers that will result in page faults
  * under normal circumstances, used to verify that nobody uses
@@ -166,4 +188,29 @@ static inline void list_move_tail(struct list_head *list,
         list_add_tail(list, head);
 }
 
+static inline void __list_splice(struct list_head *list,
+                                 struct list_head *head)
+{
+        struct list_head *first = list->next;
+        struct list_head *last = list->prev;
+        struct list_head *at = head->next;
+
+        first->prev = head;
+        head->next = first;
+
+        last->next = at;
+        at->prev = last;
+}
+
+/**
+ *  * list_splice - join two lists
+ *   * @list: the new list to add.
+ *    * @head: the place to add it in the first list.
+ *     */
+static inline void list_splice(struct list_head *list, struct list_head *head)
+{
+        if (!list_empty(list))
+                __list_splice(list, head);
+}
+
 #endif