[Mesa-dev] [PATCH 09/13] util/list: Add list_empty and list_length functions

Ian Romanick idr at freedesktop.org
Thu May 7 17:31:02 PDT 2015


On 05/05/2015 11:21 AM, Neil Roberts wrote:
> Jason Ekstrand <jason at jlekstrand.net> writes:
> 
>> +static inline bool list_empty(struct list_head *list)
>> +{
>> +   return list->next == list;
>> +}
> 
> It would be good if list.h also included stdbool.h in order to get the
> declaration of bool. However, will that cause problems on MSVC? Is the
> Gallium code compiled on MSVC in general?
> 
>> +static inline unsigned list_length(struct list_head *list)
>> +{
>> +   unsigned length = 0;
>> +   for (struct list_head *node = list->next; node != list; node = node->next)
>> +      length++;
>> +   return length;
>> +}
> 
> Any reason not to use one of the list iterator macros here? Is it safe
> to use a C99-ism outside of a macro in this header? Maybe MSVC
> supports this particular C99-ism anyway.
> 
> For what it's worth, I'm strongly in favour of using these kernel-style
> lists instead of exec_list. The kernel ones seem much less confusing.

Huh?  They're practically identical.  The only difference is the
kernel-style lists have a single sentinel node, and that node is
impossible to identify "in a crowd."  The exec_lists use two sentinel
nodes, and those nodes have one pointer of overlapping storage (head and
tail are the next and prev pointers of one node, and tail and tail_pred
are the next and prev pointers of the other).  I thought there was some
ASCII art in list.h that showed this, but that appears to not be the case...

This gives some convenience that you can walk through a list from any
node in the list without having a pointer to the list itself.  I don't
know if we still do, but there used to be a few places where we took
advantage of that.

Some of the APIs are (very) poorly named (I'm looking at you,
insert_before), and I'd welcome patches to fix that up.

> Regards,
> - Neil
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 



More information about the mesa-dev mailing list