00001
00002
00003
00004
00005
00006
00007 #ifndef _NM_LIST
00008 #define _NM_LIST
00009
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013
00014 struct nm_list {
00015 struct nm_list *prev;
00016 struct nm_list *next;
00017 };
00018 #define NMF_LIST_INITIALIZER(l) { &(l), &(l) }
00019
00024 static inline void nm_list_init(struct nm_list *l)
00025 {
00026 l->prev = l->next = l;
00027 }
00028
00029 static inline void __list_add(struct nm_list *el, struct nm_list *prev,
00030 struct nm_list *next)
00031 {
00032
00033 next->prev = el;
00034 el->next = next;
00035 el->prev = prev;
00036 prev->next = el;
00037 }
00038
00039 static inline void nm_list_add(struct nm_list *el, struct nm_list *head)
00040 {
00041 __list_add(el, head, head->next);
00042 }
00043
00044 static inline void nm_list_add_tail(struct nm_list *el, struct nm_list *head)
00045 {
00046 __list_add(el, head->prev, head);
00047 }
00048
00049 static inline void __list_del(struct nm_list *prev, struct nm_list *next)
00050 {
00051 next->prev = prev;
00052 prev->next = next;
00053 }
00054
00055 static inline void nm_list_del(struct nm_list *entry)
00056 {
00057 __list_del(entry->prev, entry->next);
00058 }
00059
00060 static inline void nm_list_del_init(struct nm_list *entry)
00061 {
00062 __list_del(entry->prev, entry->next);
00063 nm_list_init(entry);
00064 }
00065
00066 static inline int nm_list_empty(struct nm_list *entry)
00067 {
00068 return entry->next == entry;
00069 }
00070
00071 static inline struct nm_list * nm_list_del_head_ret(struct nm_list *head)
00072 {
00073 struct nm_list *e;
00074 if (nm_list_empty(head))
00075 return NULL;
00076
00077 e = head->next;
00078 nm_list_del(e);
00079
00080 return e;
00081 }
00082
00083 #define nm_list_entry(ptr, type, member) \
00084 nm_container_of(ptr, type, member)
00085
00095 #define nm_list_for_each(pos, head) \
00096 for (pos = (head)->next; pos != (head); pos = pos->next)
00097
00110 #define nm_list_for_each_entry(pos, head, member)\
00111 for (pos = nm_list_entry((head)->next, __typeof__(*pos), member);\
00112 &(pos->member) != (head);\
00113 pos = nm_list_entry(pos->member.next, __typeof__(*pos), member))
00114
00115 #ifdef __cplusplus
00116 }
00117 #endif
00118
00119 #endif