Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: Re: [OMPI devel] RFC: opal_list iteration macros
From: Jeff Squyres (jsquyres) (jsquyres_at_[hidden])
Date: 2013-01-29 12:22:09


Agreed. I like the idea, and recognize that it is inspired by Linux kernel macros. But I would prefer them to be upper case to match our conventions.

Also, please be sure to put in good comments explaining their use in the .h file.

Thanks!

On Jan 29, 2013, at 12:18 PM, Ralph Castain <rhc_at_[hidden]> wrote:

> Ja, I've considered a similar addition on occasion. +1 from me
>
> Only comment: you should change these to match our convention by making the macros be capital letters: e.g., OPAL_LIST_FOREACH
>
> On Jan 29, 2013, at 9:08 AM, Nathan Hjelm <hjelmn_at_[hidden]> wrote:
>
>> What: Add two new macros to opal_list.h:
>>
>> #define opal_list_foreach(item, list, type) \
>> for (item = (type *) (list)->opal_list_sentinel.opal_list_next ; \
>> item != (type *) &(list)->opal_list_sentinel ; \
>> item = (type *) ((opal_list_item_t *) (item))->opal_list_next)
>>
>> #define opal_list_foreach_safe(item, next, list, type) \
>> for (item = (type *) (list)->opal_list_sentinel.opal_list_next, \
>> next = (type *) ((opal_list_item_t *) (item))->opal_list_next ;\
>> item != (type *) &(list)->opal_list_sentinel ; \
>> item = next, next = (type *) ((opal_list_item_t *) (item))->opal_list_next)
>>
>> The first macro provides a simple iterator over an unchanging list and the second macro is safe for opal_list_item_remove(item).
>>
>> Why: These macros provide a clean way to do the following:
>>
>> for (item = opal_list_get_first (list) ;
>> item != opal_list_get_end (list) ;
>> item = opal_list_get_next (item)) {
>> some_class_t *foo = (some_class_t *) foo;
>> ...
>> }
>>
>> becomes:
>>
>> some_class_t *foo;
>>
>> opal_list_foreach(foo, list, some_class_t) {
>> ...
>> }
>>
>> When: This is a very simple addition but I wanted to give a heads up on the devel list because these macros are different from what we usually provide (though they should look familiar to those familiar with the Linux kernel). I intend to commit these macros to the truck (and CMR for 1.7.1) tomorrow (Wed 01/29/13) around 12:00 PM MST.
>>
>> Thoughs? Comments?
>>
>> -Nathan Hjelm
>> HPC-3, LANL
>> _______________________________________________
>> devel mailing list
>> devel_at_[hidden]
>> http://www.open-mpi.org/mailman/listinfo.cgi/devel
>
>
> _______________________________________________
> devel mailing list
> devel_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/devel

-- 
Jeff Squyres
jsquyres_at_[hidden]
For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/