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

[十月往昔]——Linux内核中的list.h浅谈

为什么要叫做“十月往昔”呢,是为了纪念我的原博客,http://www.casual0402.cn。
不知道为什么,突然想来一个新的开始——而那个博客存活至今刚好十个月,也有十个月里的文档。
十月往昔,总有一些觉得珍贵的,所以搬迁到这里来。
而这篇文章是在09.04.10里写的。
终归是一家之谈。
Jason Lee
 
————————————–cut-line
/*-------------------------------
include/linux/list.h -2.6.29
*/
该文件包含:
1#ifndef _LINUX_LIST_H
2#define _LINUX_LIST_H
3
4#include <linux/stddef.h>
5#include <linux/poison.h>
6#include <linux/prefetch.h>
7#include <asm/system.h>
 
 
链表的初始化
19struct list_head {
20 struct list_head *next, *prev;
21};
22
23#define LIST_HEAD_INIT(name) { &(name), &(name) }
24
25#define LIST_HEAD(name) \
26 struct list_head name = LIST_HEAD_INIT(name)
27
28static inline void INIT_LIST_HEAD(struct list_head *list)
29{
30 list->next = list;
31 list->prev = list;
32}
19-21
行定义了一个list_head
结构,只有两个指向list_head
结构的指针,一个next
,一个prev
,作用显而易见。
23
行的宏LIST_HEAD_INIT(name)
与25
行的宏LIST_HEAD(name)
组合进行链表的初始化,即next
和prev
都指向自身。
25
行的静态内联函数INIT_LIST_HEAD(struct list_head *list)
同样是用来初始化链表,效果同上述一点。GNU
下的C
语言对C
进行了扩充,不再是ANSI C
,它里面增添了很多C++
的特性,所以对内核进行编译只能选用相应的GCC

INIT_LIST_HEAD
在有的文献中是以宏的形式出现:
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
 
 
链表的插入
34/*
35 * Insert a new entry between two known consecutive entries.
36 *
37 * This is only for internal list manipulation where we know
38 * the prev/next entries already!
39 */
40#ifndef CONFIG_DEBUG_LIST
41static inline void __list_add(struct list_head *new,
42 struct list_head *prev,
43 struct list_head *next)


相关文档:

实战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 Kernel Threads in Device Drivers

 Purpose
This examples shows how to create and stop a kernel thread.
The driver is implemented as a loadable module. In the init_module() routine five kernel threads are created. This kernel threads sleep one second, wake up, print a message and fall asleep again. On unload of the module (cle ......

linux 双网卡服务器NAT服务

debian lenny , my favorite
a. vim  /etc/sysctl.conf:
    modify net.ipv4.ip_forward = 1
b. flush route table:
    iptables -F
    iptables -P INPUT ACCEPT
    iptables -P FORWARD ACCEPT
c. open NAT services:
 &nb ......

linux telnet登陆慢问题

 更改/etc/resolv.conf文件
    如果你的linux主机只是在局域网内工作,请将nameserver地址改为网卡本身的地址。
    例:
    # vi /etc/resolv.conf
    nameserver 192.168.0.160
    search site
    然后 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号