易截截图软件、单文件、免安装、纯绿色、仅160KB

浅谈linux内核中的list.h[2]

链表的删除
83/*
84 * Delete a list entry by making the prev/next entries
85 * point to each other.
86 *
87 * This is only for internal list manipulation where we know
88 * the prev/next entries already!
89 */
90static inline void __list_del(struct list_head * prev, struct list_head * next)
91{
92 next->prev = prev;
93 prev->next = next;
94}
该函数通过设置prev和next指针指向彼此,实现了删除二者之间节点的功能。但是这里我有个疑惑,删除的指针的释放在哪里实现。
96/**
97 * list_del - deletes entry from list.
98 * @entry: the element to delete from the list.
99 * Note: list_empty() on entry does not return true after this, the entry is
100 * in an undefined state.
101 */
102#ifndef CONFIG_DEBUG_LIST
103static inline void list_del(struct list_head *entry)
104{
105 __list_del(entry->prev, entry->next);
106 entry->next = LIST_POISON1;
107 entry->prev = LIST_POISON2;
108}
109#else
110extern void list_del(struct list_head *entry);
111#endif
该函数通过调用上面的内联函数实现节点的删除,这里的LIST_POISON1和LIST_POISON2是在linux/poison.h定义的。此处仍然是条件编译。
 
 
链表节点的置换
113/**
114 * list_replace - replace old entry by new one
115 * @old : the element to be replaced
116 * @new : the new element to insert
117 *
118 * If @old was empty, it will be overwritten.
119 */
120static inline void list_replace(struct list_head *old,
121 struct list_head *new)
122{
123 new->next = old->next;
124 new->next->prev = new;
125 new->prev = old->prev;
126 new->prev->next = new;
127}
128
129static inline void list_replace_init(struct list_head *old,
130 struct list_head *new)
131{
132 list_replace(old, new);
133 INIT_LIST_HEAD(old);
134}
静态内联函数list_replace接受两个参数:old和new,并通过new替换old。而list_replace_init函数则是通过调用list_replace进行替换,之后调用INIT_LIST_HEAD对被替换的old进行链表初始化。
 
 
链表的移动
146/**
147 * list_move - delete from one list


相关文档:

实战Linux Bluetooth编程(六) L2CAP编程实例

例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
 如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

Linux下动态库的生成及链接方法(1)

               Linux下动态库的生成及链接方法 (1)
      Linux 下动态库文件的扩展名为".so"(Shared Object)。按照约定,所有动态库文件名的形式是libname.so(可能在名字中加入版本号)。这样,线程函数库被称作 ......

vivi与Linux kernel的参数传递情景分析 (转)

在上一部分提到过了,vivi作为bootloader,向内核传递启动参数是其本职工作之一。要把这个情景分析清楚,不仅仅需要分析vivi的参数机 制,而且要分析Linux kernel的接收机制。因为这是一个简单的通信过程,比起本科所学习的TCP/IP来简单的多,但是因为简单,所以在协议上并不规范,理解上反而不如 TCP/IP协议。下面就分为两 ......

Linux命令小记

 ~ 当前用户目录的缩写
 cd ~
 cd /home/<user-name>/
--help 获取帮助
 vi --help
tab 自动补全。双击tab给出补全提示。
 若当前命令无歧义,则完整补全。若有歧义双击可列出提示选项。
 cd /e [tab], 补全为cd /etc/
 cd /b [tab-tab], 列出选项bin/ bo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号