Links in Linux

xiaoxiao2021-03-06  98

#ifndef _linux_list_h # define _linux_list_h

/ * * These are non-NULL pointers that will result in page faults * under normal circumstances, used to verify that nobody uses * non-initialized list entries. * / # Define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 (( Void *) 0x00200200)

/ * * Simple doubly linked list implementation. * * Some of the internal functions ( "__xxx") are useful when * manipulating whole lists rather than single entries, as * sometimes we already know the next / prev entries and we can * generate better Code by Using Them Directly Rather Than * Using The Generic Single-Entry Routines. * /

Struct List_head {structure list_head * next, * prev;};

#define list_head_init (name) {& (Name), & (name)}

#define list_head (name) / struct list_Head name = list_head_init (name)

#define init_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 list manipulation where we know * the prev / next entries already! * / Static inline void __list_add (struct list_head * new, struct list_head * prev, Struct list_head * next) {next-> prev = new; new-> next = next; new-> prev = prev; prev-> next = new;}

/ ** * list_add - add a new entry * @new: new entry to be added * @HEAD: list head to add it after * * Insert a new entry after the specified head. * This is good for import. * / Static inline void list_add (struct list_head * new, struct list_head * head) {__list_add (new, head, head-> next);}

/ ** * list_add_tail - add a new entry * @new: new entry to be added * @head: list head to add it before * * Insert a new entry before the specified head * This is useful for implementing queues * /.. static inline void list_add_tail (struct list_head * new, struct list_head * head) {__list_add (new, head-> prev, head);} / * * Delete a list entry by making the prev / next entries * point to each other *. * This is only for internal list manipulation where we know * the prev / next entries already * / static inline void __list_del (struct list_head * prev, struct list_head * next) {next-> prev = prev;! prev-> next = next }

/ ** * list_del - deletes entry from list * @entry:.. The element to delete from the list * Note: list_empty on entry does not return true after this, the entry is * in an undefined state * / static inline void. List_del (struct list_head * entry) {__list_del (entry-> prev, entry-> next); entry-> next = list_poison1; entry-> prev = list_poison2;}

/ ** * list_del_init - deletes entry from list and reinitialize it * @entry: the element to delete from the list * / static inline void list_del_init (struct list_head * entry) {__list_del (entry-> prev, entry-> next.. ); Init_list_head (entry);

/ ** * list_move - delete from one list and add as another's head * @list: the entry to move * @head: the head that will precede our entry * / static inline void list_move (struct list_head * list, struct list_head * head ) {__List_del (list-> prev, list-> next); list_add (list, head);

/ ** * list_move_tail - delete from one list and add as another's tail * @list: the entry to move * @head: the head that will follow our entry * / static inline void list_move_tail (struct list_head * list, struct list_head * head ) {__List_del (list-> prev, list-> next); list_add_tail (list, head);} / ** * list_empty - tests WHETHER A LIST IS EMPTY * @HEAD: The list to test. * / Static inline int list_empty (const struct list_head * head) {return head-> next == head;

/ ** * list_empty_careful - tests whether a list is * empty _and_ checks that no other CPU might be * in the process of still modifying either member * * NOTE: using list_empty_careful () without synchronization * can only be safe if the only activity that can happen * to the list entry is list_del_init () Eg it can not be used * if another CPU could re-list_add () it * * @head:.... the list to test * / static inline int list_empty_careful (const struct list_head * Head) {structure list_head * next = head-> next; return (next == head) && (next == head-> prev);

static inline void __list_splice (struct list_head * list, struct list_head * head) {struct list_head * first = list-> next; struct list_head * last = list-> prev; struct list_head * at = head-> next;

First-> prev = head; Head-> next = first;

Last-> next = at; at-> prev = last;}

/ ** * list_splice - join two lists * @list: the new list to add * @head: the place to add it in the first list * / static inline void list_splice (struct list_head * list, struct list_head * head).. {If (! List_empty (list)) __list_splice (list, head);}

/ ** * list_splice_init - Join Lists and reinitialise the Emptied List. * @List: The new list to add. * @HEAD: The Place to add it in the first list. * * The list at @list is reinitialiad * / static inline void list_splice_init (struct list_head * list, struct list_head * head) {(! list_empty (list)) if {__list_splice (list, head); INIT_LIST_HEAD (list);}} / ** * list_entry - get the struct for this entry * @ptr: the & struct list_head pointer * @type:. the type of the struct this is embedded in * @member:.. the name of the list_struct within the struct * / # define list_entry (ptr, type, member) / Container_of (PTR, Type, Member)

/ ** * list_for_each - iterate over a list * @pos: The & struct list_head to use as a loop counter. * @Head: the head for your list. * / # Define list_for_each (pos, head) / for (POS = HEAD -> Next, Prefetch; POS! = (head); / POS = POS-> Next, Prefetch (POS-> Next))

/ ** * __list_for_each - iterate over a list * @pos: the & struct list_head to use as a loop counter * @head: the head for your list * * This variant differs from list_for_each () in that it's the * simplest possible.. List Iteration Code, No Prefetching Is Done. * Use this for code That Knows The List to Be Very Short (Empty * or 1 Entry) MOST OF THE TIME. * / # Define __list_for_each (pOS, head) / for (POS = HEAD -> Next; POS! = (head); POS = POS-> Next)

/ ** * list_for_each_prev - iterate over a list backwards * @pos: the & struct list_head to use as a loop counter * @head: the head for your list * / # define list_for_each_prev (pos, head) / for (pos =.. (HEAD) -> prev, prefeetch; POS! = (hEAD); / POS = POS-> prev, prefetch (pOS-> prev)) / ** * list_for_each_safe - Itereate over a list Safe Against removal of list entry * @pos: the & struct list_head to use as a loop counter * @n:. another & struct list_head to use as temporary storage * @head:. the head for your list * / # define list_for_each_safe (pos, n, HEAD / for (POS = (head) -> next, n = pos -> next; pOS! = (hEAD); / POS = N, n = POS-> Next) / ** * list_for_each_entry - Iterage Over List of given type * @pos: the type * to use as a loop counter * @head:.. the head for your list * @member:. the name of the list_struct within the struct * / # define list_for_each_entry (pos, head, member ) / For (pOS = list_entry ((head) -> Next, TypeOf (* POS), Member, / Prefetch (POS-> MEMBER .NEXT); / & POS-> Member! = (head); / pOS = list_entry (POS-> Member.next, TypeOf (* POS), Member), / Prefetch (POS-> Member.Next))

/ ** * list_for_each_entry_reverse - iterate backwards over list of given type * @pos: the type * to use as a loop counter * @head: the head for your list * @member: the name of the list_struct within the struct... * / # Define list_for_each_entry_reverse (POS, Head, Member) / for (POS = List_ENTRY ((HEAD) -> Prev, TypeOf (* POS), Member, / Prefetch (POS-> Member.Prev); / & POS > MEMBER! = (Head); / POS = List_ENTRY (POS-> Member.Prev, TypeOf (* POS), Member), / Prefetch (POS-> Member.PREV)) / ** * list_prepare_entry - prepare a Pos Entry for use as a start point in * list_for_each_entry_continue * @pos: the type * to use as a start point * @head: the head of the list * @member:. the name of the list_struct within the struct * / # define list_prepare_entry ( POS, HEAD, MEMBER / ((POS)?: list_entry (Head, TypeOf (* POS), Member)

.. / ** * list_for_each_entry_continue - iterate over list of given type * continuing after existing point * @pos: the type * to use as a loop counter * @head: the head for your list * @member: the name of the list_struct WITHIN THE STRUCT. * / # Define List_for_each_entry_continue (POS, Head, Member) / for (POS = LIST_ENTRY (POS-> Member.next, TypeOf (* POS), Member), / Prefetch (POS-> Member.Next); / & Pos-> MEMBER! = (Head); / pOS = list_entry (POS-> Member.next, TypeOf (* POS), Member), / Prefetch (POS-> Member.Next))

/ ** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry * @pos: the type * to use as a loop counter * @n: another type * to use as temporary storage * @head: the head. For Your List. * @member: The name of the list_struct within the structure. * / # define list_for_each_entry_safe (pOS, N, Head, Member) / for (POS = list_entry ((head) -> Next, Typeof (* POS) , MEMBER, / N = List_ENTRY (POS-> Member.next, TypeOf (* POS), Member); / & POS-> Member! = (HEAD); / POS = N, N = List_entry (n-> member. Next, TypeOf (* n), member) # ENDIF

转载请注明原文地址:https://www.9cbs.com/read-123588.html

New Post(0)