Hi Robert,

On Sat, Nov 20, 2010 at 11:17 PM, Robert P. J. Day
<rpj...@crashcourse.ca> wrote:
> On Sat, 20 Nov 2010, Dave Hylands wrote:
...snip...
>> And this is why routines like list_is_last need to be passed in the
>> node to test along with the head of the list.
>
>  huh ... i never knew that test routine even existed:
>
>
> static inline int list_is_last(const struct list_head *list,
>                                const struct list_head *head)
> {
>        return list->next == head;
> }
>
>
>  it of course just reinforces what i wrote -- that you better not
> ever lose track of which node in a list is the "head" because there's
> no way to ever recover it.
>
>  i'm wondering, though, how useful a test of "list_is_last()" really
> is.  normally, if you want to iterate through a list, you'll use the
> standard "list_for_each()" or "list_for_each_entry()" constructs,
> which will handle all the iteration for you.  and you'll stop at the
> end of the list nodes without processing the "head" node, anyway.

If you need to hold a lock to traverse the list, and the operations on
each node took a considerable amount of time, you might want to
traverse the list manually, acquiring and releasing the list lock at
appropriate places along the way, rather than using a construct like
list_for_each. Especially if nodes could be deleted from the list.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to