Linux内核链表list_head扩展---klist(三)

2014-11-24 08:54:32 ? 作者: ? 浏览: 3
jects (necessary for safe
81 * deletion) then the get/put arguments are used to initialise
82 * functions that take and release references on the embedding
83 * objects.
84 */
/* klist初始化接口
* get/put方法用来操作klist_node
*/
85void klist_init(struct klist *k, void (*get)(struct klist_node *),
86 void (*put)(struct klist_node *))
87{
88 INIT_LIST_HEAD(&k->k_list);
89 spin_lock_init(&k->k_lock);
90 k->get = get;
91 k->put = put;
92}
93EXPORT_SYMBOL_GPL(klist_init);
94
/* 将节点加入到链表头 */
95static void add_head(struct klist *k, struct klist_node *n)
96{
97 spin_lock(&k->k_lock);
98 list_add(&n->n_node, &k->k_list);
99 spin_unlock(&k->k_lock);
100}
101
/* 将节点加入到链表尾 */
102static void add_tail(struct klist *k, struct klist_node *n)
103{
104 spin_lock(&k->k_lock);
105 list_add_tail(&n->n_node, &k->k_list);
106 spin_unlock(&k->k_lock);
107}
108
/* 节点初始化
* 包括初始化链表、引用计数、设置指向klist
*/
109static void klist_node_init(struct klist *k, struct klist_node *n)
110{
111 INIT_LIST_HEAD(&n->n_node);
112 kref_init(&n->n_ref);
113 knode_set_klist(n, k);
/* 如果klist的get方法存在,则调用获取节点 */
114 if (k->get)
115 k->get(n);
116}
117
118/**
119 * klist_add_head - Initialize a klist_node and add it to front.
120 * @n: node we're adding.
121 * @k: klist it's going on.
122 */
/* 将节点n初始化并加入到klist的头 */
123void klist_add_head(struct klist_node *n, struct klist *k)
124{
125 klist_node_init(k, n);
126 add_head(k, n);
127}
128EXPORT_SYMBOL_GPL(klist_add_head);
129
130/**
131 * klist_add_tail - Initialize a klist_node and add it to back.
132 * @n: node we're adding.
133 * @k: klist it's going on.
134 */
/* 将节点n初始化并加入到klist的尾 */
135void klist_add_tail(struct klist_node *n, struct klist *k)
136{
137 klist_node_init(k, n);
138 add_tail(k, n);
139}
140EXPORT_SYMBOL_GPL(klist_add_tail);
141
142/**
143 * klist_add_after - Init a klist_node and add it after an existing node
144 * @n: node we're adding.
145 * @pos: node to put @n after
146 */
/* 在节点pos后面插入节点n */
147void klist_add_after(struct klist_node *n, struct klist_node *pos)
148{
149 struct klist *k = knode_klist(pos);
150
151 klist_node_init(k, n);
152 spin_lock(&k->k_lock);
153 list_add(&n->n_node, &pos->n_node);
154 spin_unlock(&k->k_lock);
155}
156EXPORT_SYMBOL_GPL(klist_add_after);
157
158/**
159 * klist_add_before - Init a klist_node and add it before an existing node
160 * @n: node we're adding.
161 * @pos: node to put @n after
162 */
/* 在节点pos前面插入节点n */
163void klist_add_before(struct klist_node *n, struct klist_node *pos)
164{
165 struct klist *k = knode_klist(pos);
166
167 klist_node_init(k, n);
168 spin_lock(&k->k_lock);
169 list_add_tail(&n->n_node, &pos->n_node);
170 spin_unlock(&k->k_lock);
171}
172EXPORT_SYMBOL_GPL(klist_add_before);
173
/* 等待者结构体,用于删除节点,删除完成唤醒进程 */
174struct klist_waiter {
175 struct list_head list;
176 struct klist_node *node;
177 struct task_struct *process;
178 int woken;
179};
180
/* 定义并初始化klist节点移除自旋锁 */
181static DEFINE_SPINLOCK(klist_remove_lock);
/* 定义一个等待器的链表 */
182static LIST_HEAD(klis
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: