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: Ralph Castain (rhc_at_[hidden])
Date: 2013-01-29 12:18:05


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