Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |  

This web mail archive is frozen.

This page is part of a frozen web archive of this mailing list.

You can still navigate around this archive, but know that no new mails have been added to it since July of 2016.

Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.

Subject: [OMPI devel] RFC: opal_list iteration macros
From: Nathan Hjelm (hjelmn_at_[hidden])
Date: 2013-01-29 12:08:52


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