首页 > 其他 > 详细

内核分析阅读笔记

时间:2014-02-24 20:12:36      阅读:394      评论:0      收藏:0      [点我收藏+]

include/Linux/stddef.h中macro offsetof define,list:

#define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

offsetof macro对于上述示例的展开剂分析:&((struct example_struct *)0)->list表示当结构example_struct正好在地址0上时其成员list的地址,即成员位移.

traverse linked list member element;

下面使用list_entry macro遍历链表得到链表指针,再从链表指针映射回对应结构example_struct的指针,然后,对其成员priority进行操作,函数example_add_entry的功能是给链表加入新的结构成员

void example_add_entry(struct example_struct *new)

{

  struct list_head *ptr;

  struct example_struct *entry;

  //遍历链表

  for (ptr = example_list.next;ptr != &example_list;ptr = ptr->next) {

  //映射回 对应结构example_struct的指针

  entry = list_entry(ptr,struct todo_Struct,list);

  

}

}

内核分析阅读笔记

原文:http://www.cnblogs.com/ruiy/p/linked.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!