Skip to content

Commit 3a036f8

Browse files
hjelmnjsquyres
authored andcommitted
opal/class: add additional object helper functions
This commit adds two additional helpers to opal/class: - OPAL_HASH_TABLE_FOREACH_PTR: Same as OPAL_HASH_TABLE_FOREACH but operating on ptr hash tables. This is needed because the _ptr iterator functions take an additional argument. - OPAL_LIST_FOREACH_DECL: Same as OPAL_LIST_FOREACH but declares the variable specified in the first argument. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
1 parent 1b6622f commit 3a036f8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

opal/class/opal_hash_table.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ OPAL_DECLSPEC int opal_proc_table_get_next_key(opal_proc_table_t *pt, opal_proce
486486
for (void *_nptr=NULL; \
487487
OPAL_SUCCESS == opal_hash_table_get_next_key_##type(ht, &key, (void **)&value, _nptr, &_nptr);)
488488

489+
#define OPAL_HASH_TABLE_FOREACH_PTR(key, value, ht, body) \
490+
{ \
491+
size_t key_size_; \
492+
for (void *_nptr=NULL; \
493+
OPAL_SUCCESS == opal_hash_table_get_next_key_ptr (ht, &key, &key_size_, (void **)&value, _nptr, &_nptr);) \
494+
body \
495+
}
489496
END_C_DECLS
490497

491498
#endif /* OPAL_HASH_TABLE_H */

opal/class/opal_list.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ typedef struct opal_list_t opal_list_t;
215215
item != (type *) &(list)->opal_list_sentinel ; \
216216
item = (type *) ((opal_list_item_t *) (item))->opal_list_next)
217217

218+
#define OPAL_LIST_FOREACH_DECL(item, list, type) \
219+
for (type *item = (type *) (list)->opal_list_sentinel.opal_list_next ; \
220+
item != (type *) &(list)->opal_list_sentinel ; \
221+
item = (type *) ((opal_list_item_t *) (item))->opal_list_next)
222+
218223
/**
219224
* Loop over a list in reverse.
220225
*

0 commit comments

Comments
 (0)