op_list.h
Go to the documentation of this file.00001
00011 #ifndef OP_LIST_H
00012 #define OP_LIST_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 struct list_head {
00025 struct list_head * next, * prev;
00026 };
00027
00034 static __inline__ void list_init(struct list_head * ptr)
00035 {
00036 ptr->next = ptr;
00037 ptr->prev = ptr;
00038 }
00039
00040
00041
00042
00043
00044
00045
00046 static __inline__ void __list_add(struct list_head * new_entry,
00047 struct list_head * prev,
00048 struct list_head * next)
00049 {
00050 next->prev = new_entry;
00051 new_entry->next = next;
00052 new_entry->prev = prev;
00053 prev->next = new_entry;
00054 }
00055
00064 static __inline__ void list_add(struct list_head * new_entry, struct list_head * head)
00065 {
00066 __list_add(new_entry, head, head->next);
00067 }
00068
00077 static __inline__ void list_add_tail(struct list_head * new_entry, struct list_head * head)
00078 {
00079 __list_add(new_entry, head->prev, head);
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089 static __inline__ void __list_del(struct list_head * prev,
00090 struct list_head * next)
00091 {
00092 next->prev = prev;
00093 prev->next = next;
00094 }
00095
00101 static __inline__ void list_del(struct list_head * entry)
00102 {
00103 __list_del(entry->prev, entry->next);
00104 }
00105
00110 static __inline__ void list_del_init(struct list_head * entry)
00111 {
00112 __list_del(entry->prev, entry->next);
00113 list_init(entry);
00114 }
00115
00120 static __inline__ int list_empty(struct list_head const * head)
00121 {
00122 return head->next == head;
00123 }
00124
00130 static __inline__ void list_splice(struct list_head * list, struct list_head * head)
00131 {
00132 struct list_head * first = list->next;
00133
00134 if (first != list) {
00135 struct list_head * last = list->prev;
00136 struct list_head * at = head->next;
00137
00138 first->prev = head;
00139 head->next = first;
00140
00141 last->next = at;
00142 at->prev = last;
00143 }
00144 }
00145
00152 #define list_entry(ptr, type, member) \
00153 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
00154
00160 #define list_for_each(pos, head) \
00161 for (pos = (head)->next; pos != (head); pos = pos->next)
00162
00169 #define list_for_each_safe(pos, n, head) \
00170 for (pos = (head)->next, n = pos->next; pos != (head); \
00171 pos = n, n = pos->next)
00172
00173 #define LIST_HEAD_INIT(name) { &(name), &(name) }
00174
00175 #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
00176
00177 #endif