linux list

linux list

1. container_of

#define container_of(ptr, type, member) /
({                                                        /
    const typeof( ((type *)0)->member ) *__mptr = (ptr);/
    (type *)( (char *)__mptr - offsetof(type,member) ); /
})

經過成員指針獲得容器指針。html

2. struct list_head

struct list_head {
    struct list_head *next, *prev;
};

3. list_entry

#define list_entry(ptr, type, member) /
    container_of(ptr, type, member)

4. list_for_each

#define list_for_each(pos, head) \ 
    for (pos = (head)->next, prefetch(pos->next); pos != (head); \  
        pos = pos->next, prefetch(pos->next))

5. list_for_each_entry

#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))
相關文章
相關標籤/搜索