Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / include / libcfs / list.h
similarity index 87%
rename from lnet/include/linux/lustre_list.h
rename to lnet/include/libcfs/list.h
index a218f2c..eebb7b6 100644 (file)
@@ -1,9 +1,16 @@
-#ifndef _LUSTRE_LIST_H
-#define _LUSTRE_LIST_H
+#ifndef __LIBCFS_LIST_H__
+#define __LIBCFS_LIST_H__
+
+#if defined (__linux__) && defined(__KERNEL__)
 
-#ifdef __KERNEL__
 #include <linux/list.h>
-#else
+
+#define CFS_LIST_HEAD_INIT(n)          LIST_HEAD_INIT(n)
+#define CFS_LIST_HEAD(n)               LIST_HEAD(n)
+#define CFS_INIT_LIST_HEAD(p)          INIT_LIST_HEAD(p)
+
+#else /* !defined (__linux__) && defined(__KERNEL__) */
+
 /*
  * Simple doubly linked list implementation.
  *
@@ -22,15 +29,22 @@ struct list_head {
 
 typedef struct list_head list_t;
 
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define CFS_LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#define LIST_HEAD(name) \
+#define CFS_LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)
 
-#define INIT_LIST_HEAD(ptr) do { \
+#define CFS_INIT_LIST_HEAD(ptr) do { \
        (ptr)->next = (ptr); (ptr)->prev = (ptr); \
 } while (0)
 
+#ifndef __APPLE__
+#define LIST_HEAD(n)           CFS_LIST_HEAD(n)
+#endif
+
+#define LIST_HEAD_INIT(n)      CFS_LIST_HEAD_INIT(n)
+#define INIT_LIST_HEAD(p)      CFS_INIT_LIST_HEAD(p)
+
 /*
  * Insert a new entry between two known consecutive entries.
  *
@@ -103,7 +117,7 @@ static inline void list_del(struct list_head *entry)
 static inline void list_del_init(struct list_head *entry)
 {
        __list_del(entry->prev, entry->next);
-       INIT_LIST_HEAD(entry);
+       CFS_INIT_LIST_HEAD(entry);
 }
 
 /**
@@ -175,7 +189,7 @@ static inline void list_splice_init(struct list_head *list,
 {
        if (!list_empty(list)) {
                __list_splice(list, head);
-               INIT_LIST_HEAD(list);
+               CFS_INIT_LIST_HEAD(list);
        }
 }
 
@@ -198,15 +212,6 @@ static inline void list_splice_init(struct list_head *list,
                pos = pos->next, prefetch(pos->next))
 
 /**
- * list_for_each_prev  -       iterate over a list in reverse order
- * @pos:       the &struct list_head to use as a loop counter.
- * @head:      the head for your list.
- */
-#define list_for_each_prev(pos, head) \
-       for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
-               pos = pos->prev, prefetch(pos->prev))
-
-/**
  * list_for_each_safe  -       iterate over a list safe against removal of list entry
  * @pos:       the &struct list_head to use as a loop counter.
  * @n:         another &struct list_head to use as temporary storage
@@ -216,6 +221,21 @@ static inline void list_splice_init(struct list_head *list,
        for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)
 
+#endif /* __linux__*/
+
+#ifndef list_for_each_prev
+/**
+ * list_for_each_prev  -       iterate over a list in reverse order
+ * @pos:       the &struct list_head to use as a loop counter.
+ * @head:      the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+       for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
+               pos = pos->prev, prefetch(pos->prev))
+
+#endif /* list_for_each_prev */
+
+#ifndef list_for_each_entry
 /**
  * list_for_each_entry  -       iterate over list of given type
  * @pos:        the type * to use as a loop counter.
@@ -228,7 +248,9 @@ static inline void list_splice_init(struct list_head *list,
             &pos->member != (head);                                    \
             pos = list_entry(pos->member.next, typeof(*pos), member),  \
             prefetch(pos->member.next))
+#endif /* list_for_each_entry */
 
+#ifndef list_for_each_entry_safe
 /**
  * list_for_each_entry_safe  -       iterate over list of given type safe against removal of list entry
  * @pos:        the type * to use as a loop counter.
@@ -241,6 +263,6 @@ static inline void list_splice_init(struct list_head *list,
                n = list_entry(pos->member.next, typeof(*pos), member); \
             &pos->member != (head);                                    \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#endif /* list_for_each_entry_safe */
 
-#endif /* if !__KERNEL__*/
-#endif /* if !_LUSTRE_LIST_H */
+#endif /* __LIBCFS_LUSTRE_LIST_H__ */