码迷,mamicode.com
首页 > 系统相关 > 详细

linux list

时间:2019-05-03 18:31:21      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:tag   lang   contain   height   nbsp   line   mil   0.12   ros   

linux list

1. container_of

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

通过成员指针得到容器指针。

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))

linux list

标签:tag   lang   contain   height   nbsp   line   mil   0.12   ros   

原文地址:https://www.cnblogs.com/gr-nick/p/10805616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!