关闭

内核数据结构:链表,队列,映射二叉树

271人阅读 评论(0) 收藏 举报

链表代码在<linux/list.h>中声明,其数据结构很简单:

struct list_head {

            struct list_head *next;

            struct list_head *prev;

};

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
 struct list_head name = LIST_HEAD_INIT(name)

static inline void INIT_LIST_HEAD(struct list_head *list)
{
 list->next = list;
 list->prev = list;
}
/**
 * container_of - cast a member of a structure out to the containing structure
 * @ptr: the pointer to the member.
 * @type: the type of the container struct this is embedded in.
 * @member: the name of the member within the struct.
 *
 */
#define container_of(ptr, type, member) ({   \
 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
 (type *)( (char *)__mptr - offsetof(type,member) );})

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:88579次
    • 积分:1294
    • 等级:
    • 排名:千里之外
    • 原创:41篇
    • 转载:49篇
    • 译文:0篇
    • 评论:1条
    最新评论