[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 |
|
---|
| 3 | #include "list.h"
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
| 6 | * Insert a new entry between two known consecutive entries.
|
---|
| 7 | *
|
---|
| 8 | * This is only for internal list manipulation where we know
|
---|
| 9 | * the prev/next entries already!
|
---|
| 10 | */
|
---|
| 11 | void __list_add(struct list_head * add,
|
---|
| 12 | struct list_head * prev,
|
---|
| 13 | struct list_head * next)
|
---|
| 14 | {
|
---|
| 15 | next->prev = add;
|
---|
| 16 | add->next = next;
|
---|
| 17 | add->prev = prev;
|
---|
| 18 | prev->next = add;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | /*
|
---|
| 22 | * list_add - add a new entry
|
---|
| 23 | * @add: new entry to be added
|
---|
| 24 | * @head: list head to add it after
|
---|
| 25 | *
|
---|
| 26 | * Insert a new entry after the specified head.
|
---|
| 27 | * This is good for implementing stacks.
|
---|
| 28 | */
|
---|
| 29 | void list_add(struct list_head *add, struct list_head *head)
|
---|
| 30 | {
|
---|
| 31 | __list_add(add, head, head->next);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * list_add_tail - add a new entry
|
---|
| 36 | * @add: new entry to be added
|
---|
| 37 | * @head: list head to add it before
|
---|
| 38 | *
|
---|
| 39 | * Insert a new entry before the specified head.
|
---|
| 40 | * This is useful for implementing queues.
|
---|
| 41 | */
|
---|
| 42 | void list_add_tail(struct list_head *add, struct list_head *head)
|
---|
| 43 | {
|
---|
| 44 | __list_add(add, head->prev, head);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | * Delete a list entry by making the prev/next entries
|
---|
| 49 | * point to each other.
|
---|
| 50 | *
|
---|
| 51 | * This is only for internal list manipulation where we know
|
---|
| 52 | * the prev/next entries already!
|
---|
| 53 | */
|
---|
| 54 | void __list_del(struct list_head * prev, struct list_head * next)
|
---|
| 55 | {
|
---|
| 56 | next->prev = prev;
|
---|
| 57 | prev->next = next;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /*
|
---|
| 61 | * list_del - deletes entry from list.
|
---|
| 62 | * @entry: the element to delete from the list.
|
---|
| 63 | *
|
---|
| 64 | * list_empty() on @entry does not return true after this, @entry is
|
---|
| 65 | * in an undefined state.
|
---|
| 66 | */
|
---|
| 67 | void list_del(struct list_head *entry)
|
---|
| 68 | {
|
---|
| 69 | __list_del(entry->prev, entry->next);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /*
|
---|
| 73 | * list_del_init - deletes entry from list and reinitialize it.
|
---|
| 74 | * @entry: the element to delete from the list.
|
---|
| 75 | */
|
---|
| 76 | void list_del_init(struct list_head *entry)
|
---|
| 77 | {
|
---|
| 78 | __list_del(entry->prev, entry->next);
|
---|
| 79 | INIT_LIST_HEAD(entry);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * list_empty - tests whether a list is empty
|
---|
| 84 | * @head: the list to test.
|
---|
| 85 | */
|
---|
| 86 | int list_empty(struct list_head *head)
|
---|
| 87 | {
|
---|
| 88 | return head->next == head;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /*
|
---|
| 92 | * list_splice - join two lists
|
---|
| 93 | * @list: the new list to add.
|
---|
| 94 | * @head: the place to add it in the first list.
|
---|
| 95 | */
|
---|
| 96 | void list_splice(struct list_head *list, struct list_head *head)
|
---|
| 97 | {
|
---|
| 98 | struct list_head *first = list->next;
|
---|
| 99 |
|
---|
| 100 | if (first != list) {
|
---|
| 101 | struct list_head *last = list->prev;
|
---|
| 102 | struct list_head *at = head->next;
|
---|
| 103 |
|
---|
| 104 | first->prev = head;
|
---|
| 105 | head->next = first;
|
---|
| 106 |
|
---|
| 107 | last->next = at;
|
---|
| 108 | at->prev = last;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|