您认为tasklet_head的数据结构是否有线?

时间:2012-11-30 09:59:05

标签: linux kernel interrupt

我正在阅读tasklet的源代码并尝试理解它。

我认为tasklet_head的数据结构是有线的,你是否这么认为。 为什么第二个元素的数据类型是struct tasklet_struct **,它只是使源代码更复杂并且让人迷惑,呢? 我的意思是,作者为什么不使用struct tasklet_struct * tail? 也许作者是如此聪明,以至于我无法理解这种简单性。 如果这是真的,如果你理解它,你能否请一些提示。

398 /*
399  * Tasklets
400  */
401 struct tasklet_head
402 {
403         struct tasklet_struct *head;
404         struct tasklet_struct **tail;
405 };

可以找到完整的源代码here.

1 个答案:

答案 0 :(得分:0)

我会回答手头的编程问题。

当然*尾巴和**尾巴是完全不同的东西,这就是为什么它是**尾巴而不是*尾巴。

你将持有某种尾部引用以避免遍历整个链表以在末尾添加一些东西(对于O(1)追加而不是O(n))。尾部可能已设置为特定实例,但这种特定实施策略将有一个原因。而是指向下一个字段,它就像:

一样简单
new_item->next = NULL;
*tail = new_item;
tail = &(new_item->next);

希望这有帮助。

相关问题