- 博客(7)
- 资源 (1)
- 收藏
- 关注
转载 内核中的 likely() 与 unlikely()
内核中的 likely() 与 unlikely() 在 2.6 内核中,随处可以见到 likely() 和 unlikely() 的身影,那么为什么要用它们?它们之间有什么区别? 首先要明确: if(likely(value)) 等价于 if(value) if(unlikely(value)) 也等价于 if(value)
2015-01-06 17:07:54
337
原创 list_entry
<br />list_entry这样定义:<br /><br /> #define list_entry(ptr, type, member) /<br /> ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))<br /><br />解释:找到成员member所在容器的地址。如果是结构体的话,就是找到结构体成员变量me
2010-10-25 15:37:00
379
原创 list_for_each_safe()
<br />如果在遍历过程中,包含有删除或移动当前链接节点的操作,由于这些操作会修改遍历指针,这样会导致遍历的中端。这种情况下,必须使用list_for_each_safe宏,在操作之前将遍历指针缓存下来。内核中解释的精华部分:<br />/*<br /> list_for_each_safe -iterate over a list safe against removal of list entry<br />*/<br />#define list_for_each_s
2010-10-25 14:46:00
2103
原创 查找字符串
<br />view plaincopy to clipboardprint?<br />#include <stdio.h> <br />#include <string.h> <br />typedef int BOOL; <br />#define true 1 <br />#define false 0 <br />BOOL findsubstring(const char *bigsrc, const char *littlesrc) <br />{ <br />
2010-10-25 13:17:00
816
原创 删除字串
<br />/*判断第二个字符串是否为第一字符串的子串,如果是,则将该子串删除 <br />比如 bissrc = a123afed <br /> littlesrc = afe; <br /> 返回a123d; <br />*/ <br />#include <stdio.h> <br />#include <string.h> <br />#include <stdlib.h> <br />//判断一个字符串是否为另一个的子串,如果是,返回该子串首字母所在的位置 <br
2010-10-25 13:15:00
466
原创 字符串反转
<br />view plaincopy to clipboardprint?<br />#include <stdio.h> <br />#include <string.h> <br />void reverse_string(char *str) <br />{ <br /> char *lastchar; <br /> char tmp; <br /> for (lastchar = str; *lastchar != '/0'; lastchar++)
2010-10-25 13:14:00
240
转载 container_of
<br />问题:如何通过结构中的某个变量获取结构本身的指针???<br />关于container_of见kernel.h中:<br />/**<br />* container_of - cast a member of a structure out to the containing structure<br />* @ptr: the pointer to the member.<br />* @type: the type of the container struct this
2010-10-25 12:52:00
362
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人