I don't care the macro names. Either one is OK for me.
Thanks,
KAWASHIMA Takahiro
> Hmm, maybe something like:
>
> OPAL_LIST_FOREACH, OPAL_LISTFOREACH_REV, OPAL_LIST_FOREACH_SAFE,
> OPAL_LIST_FOREACH_REV_SAFE?
>
> -Nathan
>
> On Thu, Jan 31, 2013 at 12:36:29AM +0900, KAWASHIMA Takahiro wrote:
> > Hi,
> >
> > Agreed.
> > But how about backward traversal in addition to forward traversal?
> > e.g. OPAL_LIST_FOREACH_FW, OPAL_LIST_FOREACH_FW_SAFE,
> > OPAL_LIST_FOREACH_BW, OPAL_LIST_FOREACH_BW_SAFE
> > We sometimes search an item from the end of a list.
> >
> > Thanks,
> > KAWASHIMA Takahiro
> >
> > > 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