/* copy from linux kernel list */ #ifndef _HAIL_LIST_H_ #define _HAIL_LIST_H_ struct hail_list_head { struct hail_list_head *next, *prev; }; #define HAIL_LIST_HEAD_INIT(name) { &(name), &(name) } #define HAIL_LIST_HEAD(name) \ struct hail_list_head name = HAIL_LIST_HEAD_INIT(name) #define INIT_HAIL_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ } while (0) /* * Insert a new entry between two known consecutive entries. * * This is only for internal hail_list manipulation where we know * the prev/next entries already! */ static __inline__ void __hail_list_add(struct hail_list_head * new, struct hail_list_head * prev, struct hail_list_head * next) { next->prev = new; new->next = next; new->prev = prev; prev->next = new; } /** * hail_list_add - add a new entry * @new: new entry to be added * @head: hail_list head to add it after * * Insert a new entry after the specified head. * This is good for implementing stacks. */ static __inline__ void hail_list_add(struct hail_list_head *new, struct hail_list_head *head) { __hail_list_add(new, head, head->next); } /** * hail_list_add_tail - add a new entry * @new: new entry to be added * @head: hail_list head to add it before * * Insert a new entry before the specified head. * This is useful for implementing queues. */ static __inline__ void hail_list_add_tail(struct hail_list_head *new, struct hail_list_head *head) { __hail_list_add(new, head->prev, head); } /* * Delete a hail_list entry by making the prev/next entries * point to each other. * * This is only for internal hail_list manipulation where we know * the prev/next entries already! */ static __inline__ void __hail_list_del(struct hail_list_head * prev, struct hail_list_head * next) { next->prev = prev; prev->next = next; } /** * hail_list_del - deletes entry from hail_list. * @entry: the element to delete from the hail_list. * Note: hail_list_empty on entry does not return true after this, the entry is in an undefined state. */ static __inline__ void hail_list_del(struct hail_list_head *entry) { __hail_list_del(entry->prev, entry->next); entry->next = entry->prev = 0; } /** * hail_list_del_init - deletes entry from hail_list and reinitialize it. * @entry: the element to delete from the hail_list. */ static __inline__ void hail_list_del_init(struct hail_list_head *entry) { __hail_list_del(entry->prev, entry->next); INIT_HAIL_LIST_HEAD(entry); } /** * hail_list_empty - tests whether a hail_list is empty * @head: the hail_list to test. */ static __inline__ int hail_list_empty(struct hail_list_head *head) { return head->next == head; } /** * hail_list_splice - join two hail_lists * @hail_list: the new hail_list to add. * @head: the place to add it in the first hail_list. */ static __inline__ void hail_list_splice(struct hail_list_head *hail_list, struct hail_list_head *head) { struct hail_list_head *first = hail_list->next; if (first != hail_list) { struct hail_list_head *last = hail_list->prev; struct hail_list_head *at = head->next; first->prev = head; head->next = first; last->next = at; at->prev = last; } } /** * hail_list_entry - get the struct for this entry * @ptr: the &struct hail_list_head pointer. * @type: the type of the struct this is embedded in. * @member: the name of the hail_list_struct within the struct. */ #define hail_list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) /** * hail_list_for_each - iterate over a hail_list * @pos: the &struct hail_list_head to use as a loop counter. * @head: the head for your hail_list. */ #define hail_list_for_each(pos, head) \ for (pos = (head)->next; pos != (head); \ pos = pos->next) /** * hail_list_for_each_safe - iterate over a hail_list safe against removal of hail_list entry * @pos: the &struct hail_list_head to use as a loop counter. * @n: another &struct hail_list_head to use as temporary storage * @head: the head for your hail_list. */ #define hail_list_for_each_safe(pos, n, head) \ for (pos = (head)->next, n = pos->next; pos != (head); \ pos = n, n = pos->next) #endif /* _HAIL_LIST_H_ */