About head of kernel linked list structure
Jeff Haran
Jeff.Haran at citrix.com
Fri May 8 19:05:43 EDT 2015
From: kernelnewbies-bounces at kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of Mulyadi Santosa
Sent: Thursday, May 07, 2015 3:53 AM
To: Huaicheng Li
Cc: kernelnewbies
Subject: Re: About head of kernel linked list structure
On Wed, May 6, 2015 at 5:39 PM, Huaicheng Li <lhcwhu at gmail.com<mailto:lhcwhu at gmail.com>> wrote:
In my understanding, the head initialised using LIST_HEAD_INIT or defined by LIST_HEAD corresponds to no *real* data field.
But it *does* have its own _next_ and _prev_ pointers. The _next_ pointer points to the first real node in the doubly linked list,
and the _prev_ pointer points to the last real node.
I'm wondering if the picture shown at the very bottom of http://kernelnewbies.org/FAQ/LinkedLists is wrong about this. Because
I believe head's _prev_ should point to the last node, which is at the very right. And the last node's _next_ should point to the head.
Just as shown like the red line.
Am I right?
[cid:image002.png at 01D089A8.8896F550]
Hi Huachieng
AFAIK, if the linked list is not circular one, the last node's next should point to NULL, so does the head prev's. This is done so you know when you hit head i.e
if !(head.prev)
{
// we're at head
}
Just pointing out that these lists are circular. Back in the old days we used to call them "rings".
>From list.h:
183 /**
184 * list_empty - tests whether a list is empty
185 * @head: the list to test.
186 */
187 static inline int list_empty(const struct list_head *head)
188 {
189 return head->next == head;
190 }
Jeff Haran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150508/1377f263/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 11417 bytes
Desc: image002.png
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150508/1377f263/attachment.png
More information about the Kernelnewbies
mailing list