Re: [PATCH RFC] struct list_node

From: Rusty Russell
Date: Sun Jun 10 2007 - 20:02:39 EST


On Sun, 2007-06-10 at 10:20 -0700, Linus Torvalds wrote:
>
> On Sun, 10 Jun 2007, Rusty Russell wrote:
> >
> > The current list.h has the same type for list elements and list heads
> > even though most code and coders treat them as distinct.
>
> I think the old list.h is technically superior to yours.
>
> Exactly *because* nodes and heads are interchangeable.
>
> In fact, you are incorrect that "most code" treat them as distinct. Most
> code that uses list.h in fact uses it as a list of entries, often without
> any head at all (and each *entry* is a point of removal), because the way
> to actually *find* the structure that contains the lists is separate from
> the lists themselves.

Sorry, do you really believe a ring is "often" the case? It's not
entirely trivial to audit, but I can do a random sample of 100
list_heads.

The list iterators reinforce the "standalone head" model (ie. it's not
called list_for_each_other_entry), and they're pretty popular.

> The Linux kernel list.h is _better_ than most stupid list implementations
> that think that a head node is different from the list node. Exactly
> because it very naturally supports the notion of "this structure exists in
> a 'ring of entries'" where each node is 100% equivalent to any other node,
> and there _is_ no head.

I agree it's a wonderful feature, but you talk about "no head" but
they're all called "list_head"? In my version, they'd all be list_node,
and you can trivially treat it as a head with ->h.

It's a little more work for rings, but it's more explicit and gives us
type checking on the common case.

Thanks for your consideration,
Rusty.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/