爱问知识人 爱问教育 医院库

谁能分析下like?

首页

谁能分析下like?

谁能分析下like-linux系统下链表结构呢?

提交回答

全部答案

    2017-07-27 23:35:47
  •    2  like-linux系统下链表结构分析  3  *在like-linux系统中,链表的可移植性比较好,并不像在大学学到的链表结构那样的死板。其原理在很多linux的讲解中都有描述。  4  *原理部分可以看一下李先静老师写的《系统程序员成长之路》一书。
        5 *本文根据xenarm中的链表来具体得理一下在like-linux系统中的链表原理。  6  7 *因为时间有限,只是把相关宏定义简单扩展,并把代码做了注释和筛捡。没有成文,望各位看官见谅  8 */  9  10  11 /*  12 *定义了一个相关结构和spinlock  13 */  14 spinlock_t consistent_lock;  15 struct arm_vm_region {  16 struct list_head vm_list;  17 unsigned long vm_start;  18 unsigned long vm_end;  19 struct page *vm_pages;  20 int vm_active;  21 };  22  23 /*  24 *初始化一个链表头  25 *链表头不同于链表节点,在实际分配中,链表头存放的是边界范围等一些概括信息  26 *  27 */  28 static struct arm_vm_region consistent_head = {//初始化一个链表头  29 。
      vm_list = LIST_HEAD_INIT(consistent_head。vm_list),  30 。vm_start = CONSISTENT_BASE,  31 。vm_end = CONSISTENT_END,  32 };  33  34 static struct arm_vm_region * arm_vm_region_alloc(struct arm_vm_region *head, size_t size, gfp_t gfp)  35 {  36 //head头放的是区间总体范围  37 unsigned long addr = head->vm_start, end = head->vm_end – size;  38 unsigned long flags;  39 struct arm_vm_region *c, *new;  40  41 new = xmalloc(struct arm_vm_region);  42 if (!new)  43 goto out;  44  45 spin_lock_irqsave(&consistent_lock, flags);  46  47 /*  48 *遍历一下链表的各个节点,寻找合适的区间范围  49 *list_for_each_entry宏是一个关键,其实是一个for循环,只不过设计的比较巧妙,依靠了链表的结构  50 *其具体定义在下面  51 */  52 list_for_each_entry(c, &head->vm_list, vm_list) {  53 if ((addr + size) vm_start)//可以夹到vm_region块之间  56 goto found;  57 addr = c->vm_end;//addr 为下一个的结束地址  58 if (addr > end)  59 goto nospc;  60 }  61  62 found:  63 /*  64 * Insert this entry _before_ the one we found。
        65 */  66 list_add_tail(&new->vm_list, &c->vm_list);  67 new->vm_start = addr;  68 new->vm_end = addr + size;  69 new->vm_active = 1;  70  71 spin_unlock_irqrestore(&consistent_lock, flags);  72 return new;  73  74 nospc:  75 spin_unlock_irqrestore(&consistent_lock, flags);  76 xfree(new);  77 out:  78 return NULL;  79 }  80  81 /**  82 * list_for_each_entry - iterate over list of given type  83 * @pos: the type * to use as a loop counter。
        84 * @head: the head for your list。  85 * @member: the name of the list_struct within the struct。  86 */  87 #define list_for_each_entry(pos, head, member) \  88 for (pos = list_entry((head)->next, typeof(*pos), member); \  89 &pos->member != (head); \  90 pos = list_entry(pos->member。
      next, typeof(*pos), member))  91  92 /**  93 * list_entry – get the struct for this entry  94 * @ptr: the &struct list_head pointer。
        95 * @type: the type of the struct this is embedded in。  96 * @member: the name of the list_struct within the struct。
        97 */  98 #define list_entry(ptr, type, member) \  99 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))  100 完成 丢弃。
      

    思***

    2017-07-27 23:35:47

类似问题

换一换

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):