17 #ifndef OPENOCD_HELPER_LIST_H
18 #define OPENOCD_HELPER_LIST_H
23 #define LIST_POISON1 NULL
24 #define LIST_POISON2 NULL
49 #define LIST_HEAD_INIT(name) { &(name), &(name) }
51 #define LIST_HEAD(name) \
52 struct list_head name = LIST_HEAD_INIT(name)
67 #ifdef CONFIG_DEBUG_LIST
177 new->next = old->
next;
278 return list->
prev == head;
289 return list->
next == head;
298 return head->
next == head;
387 head->
next = new_first;
388 new_first->
prev = head;
411 (head->
next != entry && head != entry))
437 if (head->
next == entry) {
526 #define list_entry(ptr, type, member) \
527 container_of(ptr, type, member)
537 #define list_first_entry(ptr, type, member) \
538 list_entry((ptr)->next, type, member)
548 #define list_last_entry(ptr, type, member) \
549 list_entry((ptr)->prev, type, member)
559 #define list_first_entry_or_null(ptr, type, member) ({ \
560 struct list_head *head__ = (ptr); \
561 struct list_head *pos__ = head__->next; \
562 pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
570 #define list_next_entry(pos, member) \
571 list_entry((pos)->member.next, typeof(*(pos)), member)
578 #define list_prev_entry(pos, member) \
579 list_entry((pos)->member.prev, typeof(*(pos)), member)
586 #define list_for_each(pos, head) \
587 for (pos = (head)->next; pos != (head); pos = pos->next)
596 #define list_for_each_continue(pos, head) \
597 for (pos = pos->next; pos != (head); pos = pos->next)
604 #define list_for_each_prev(pos, head) \
605 for (pos = (head)->prev; pos != (head); pos = pos->prev)
613 #define list_for_each_safe(pos, n, head) \
614 for (pos = (head)->next, n = pos->next; pos != (head); \
615 pos = n, n = pos->next)
623 #define list_for_each_prev_safe(pos, n, head) \
624 for (pos = (head)->prev, n = pos->prev; \
626 pos = n, n = pos->prev)
634 #define list_entry_is_head(pos, head, member) \
635 (&pos->member == (head))
643 #define list_for_each_entry(pos, head, member) \
644 for (pos = list_first_entry(head, typeof(*pos), member); \
645 !list_entry_is_head(pos, head, member); \
646 pos = list_next_entry(pos, member))
654 #define list_for_each_entry_reverse(pos, head, member) \
655 for (pos = list_last_entry(head, typeof(*pos), member); \
656 !list_entry_is_head(pos, head, member); \
657 pos = list_prev_entry(pos, member))
666 #define list_for_each_entry_direction(forward, pos, head, member) \
667 for (pos = forward ? list_first_entry(head, typeof(*pos), member) \
668 : list_last_entry(head, typeof(*pos), member); \
669 !list_entry_is_head(pos, head, member); \
670 pos = forward ? list_next_entry(pos, member) \
671 : list_prev_entry(pos, member))
681 #define list_prepare_entry(pos, head, member) \
682 ((pos) ? (pos) : list_entry(head, typeof(*pos), member))
693 #define list_for_each_entry_continue(pos, head, member) \
694 for (pos = list_next_entry(pos, member); \
695 !list_entry_is_head(pos, head, member); \
696 pos = list_next_entry(pos, member))
707 #define list_for_each_entry_continue_reverse(pos, head, member) \
708 for (pos = list_prev_entry(pos, member); \
709 !list_entry_is_head(pos, head, member); \
710 pos = list_prev_entry(pos, member))
720 #define list_for_each_entry_from(pos, head, member) \
721 for (; !list_entry_is_head(pos, head, member); \
722 pos = list_next_entry(pos, member))
733 #define list_for_each_entry_from_reverse(pos, head, member) \
734 for (; !list_entry_is_head(pos, head, member); \
735 pos = list_prev_entry(pos, member))
744 #define list_for_each_entry_safe(pos, n, head, member) \
745 for (pos = list_first_entry(head, typeof(*pos), member), \
746 n = list_next_entry(pos, member); \
747 !list_entry_is_head(pos, head, member); \
748 pos = n, n = list_next_entry(n, member))
760 #define list_for_each_entry_safe_continue(pos, n, head, member) \
761 for (pos = list_next_entry(pos, member), \
762 n = list_next_entry(pos, member); \
763 !list_entry_is_head(pos, head, member); \
764 pos = n, n = list_next_entry(n, member))
776 #define list_for_each_entry_safe_from(pos, n, head, member) \
777 for (n = list_next_entry(pos, member); \
778 !list_entry_is_head(pos, head, member); \
779 pos = n, n = list_next_entry(n, member))
791 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
792 for (pos = list_last_entry(head, typeof(*pos), member), \
793 n = list_prev_entry(pos, member); \
794 !list_entry_is_head(pos, head, member); \
795 pos = n, n = list_prev_entry(n, member))
809 #define list_safe_reset_next(pos, n, member) \
810 n = list_next_entry(pos, member)
819 #define HLIST_HEAD_INIT { .first = NULL }
820 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
821 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
985 new->first = old->
first;
987 new->first->
pprev = &
new->first;
991 #define hlist_entry(ptr, type, member) container_of(ptr, type, member)
993 #define hlist_for_each(pos, head) \
994 for (pos = (head)->first; pos ; pos = pos->next)
996 #define hlist_for_each_safe(pos, n, head) \
997 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
1000 #define hlist_entry_safe(ptr, type, member) \
1001 ({ typeof(ptr) ____ptr = (ptr); \
1002 ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
1011 #define hlist_for_each_entry(pos, head, member) \
1012 for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
1014 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
1021 #define hlist_for_each_entry_continue(pos, member) \
1022 for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
1024 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
1031 #define hlist_for_each_entry_from(pos, member) \
1033 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
1042 #define hlist_for_each_entry_safe(pos, n, head, member) \
1043 for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
1044 pos && ({ n = pos->member.next; 1; }); \
1045 pos = hlist_entry_safe(n, typeof(*pos), member))
static void list_add(struct list_head *new, struct list_head *head)
list_add - add a new entry
static void list_splice(const struct list_head *list, struct list_head *head)
list_splice - join two lists, this is designed for stacks
static void list_bulk_move_tail(struct list_head *head, struct list_head *first, struct list_head *last)
list_bulk_move_tail - move a subsection of a list to its tail
static void __hlist_del(struct hlist_node *n)
static void __list_cut_position(struct list_head *list, struct list_head *head, struct list_head *entry)
static void list_splice_tail_init(struct list_head *list, struct list_head *head)
list_splice_tail_init - join two lists and reinitialise the emptied list
static void list_move_tail(struct list_head *list, struct list_head *head)
list_move_tail - delete from one list and add as another's tail
static void hlist_add_behind(struct hlist_node *n, struct hlist_node *prev)
hlist_add_behind - add a new entry after the one specified
static void __list_del(struct list_head *prev, struct list_head *next)
static void hlist_add_before(struct hlist_node *n, struct hlist_node *next)
hlist_add_before - add a new entry before the one specified
static void list_replace_init(struct list_head *old, struct list_head *new)
list_replace_init - replace old entry by new one and initialize the old one
static void list_cut_before(struct list_head *list, struct list_head *head, struct list_head *entry)
list_cut_before - cut a list into two, before given entry
static void hlist_del_init(struct hlist_node *n)
hlist_del_init - Delete the specified hlist_node from its list and initialize
static bool hlist_fake(struct hlist_node *h)
hlist_fake: Is this node a fake hlist?
static int list_is_first(const struct list_head *list, const struct list_head *head)
list_is_first – tests whether list is the first entry in list head
static void list_replace(struct list_head *old, struct list_head *new)
list_replace - replace old entry by new one
static int list_is_singular(const struct list_head *head)
list_is_singular - tests whether a list has just one entry.
static void INIT_HLIST_NODE(struct hlist_node *h)
static void list_del_init_careful(struct list_head *entry)
list_del_init_careful - deletes entry from list and reinitialize it.
static void list_add_tail(struct list_head *new, struct list_head *head)
list_add_tail - add a new entry
static int list_empty(const struct list_head *head)
list_empty - tests whether a list is empty
static bool hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
hlist_is_singular_node - is node the only element of the specified hlist?
static void hlist_add_fake(struct hlist_node *n)
hlist_add_fake - create a fake hlist consisting of a single headless node
static bool __list_add_valid(struct list_head *new, struct list_head *prev, struct list_head *next)
static void list_rotate_to_front(struct list_head *list, struct list_head *head)
list_rotate_to_front() - Rotate list to specific item.
static int hlist_unhashed(const struct hlist_node *h)
hlist_unhashed - Has node been removed from list and reinitialized?
static void list_cut_position(struct list_head *list, struct list_head *head, struct list_head *entry)
list_cut_position - cut a list into two
static void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
static void list_splice_init(struct list_head *list, struct list_head *head)
list_splice_init - join two lists and reinitialise the emptied list.
static bool __list_del_entry_valid(struct list_head *entry)
static void hlist_del(struct hlist_node *n)
hlist_del - Delete the specified hlist_node from its list
static void list_swap(struct list_head *entry1, struct list_head *entry2)
list_swap - replace entry1 with entry2 and re-add entry1 at entry2's position
static void __list_del_entry(struct list_head *entry)
static void list_del(struct list_head *entry)
list_del - deletes entry from list.
static int list_empty_careful(const struct list_head *head)
list_empty_careful - tests whether a list is empty and not being modified
static void __list_splice(const struct list_head *list, struct list_head *prev, struct list_head *next)
static void list_rotate_left(struct list_head *head)
list_rotate_left - rotate the list to the left
static int list_is_last(const struct list_head *list, const struct list_head *head)
list_is_last - tests whether list is the last entry in list head
static void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
hlist_add_head - add a new entry at the beginning of the hlist
static void list_del_init(struct list_head *entry)
list_del_init - deletes entry from list and reinitialize it.
static void list_splice_tail(struct list_head *list, struct list_head *head)
list_splice_tail - join two lists, each list being a queue
static void INIT_LIST_HEAD(struct list_head *list)
INIT_LIST_HEAD - Initialize a list_head structure.
static void hlist_move_list(struct hlist_head *old, struct hlist_head *new)
hlist_move_list - Move an hlist
static void list_move(struct list_head *list, struct list_head *head)
list_move - delete from one list and add as another's head
static int hlist_empty(const struct hlist_head *h)
hlist_empty - Is the specified hlist_head structure an empty hlist?
struct hlist_node * first
struct hlist_node ** pprev