diff options
author | Ben Pfaff <blp@nicira.com> | 2014-07-29 09:02:23 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2014-07-29 09:02:23 -0700 |
commit | 6bc3bb829c5fbcd77a1fd3ee18dbaea49b464e8f (patch) | |
tree | e8e8776bb2413df7f2a3b5ee43453d83f3e5e9f1 /lib/cmap.h | |
parent | 022ad2b9ce034c888ea47fd69d72025789b9ba7d (diff) | |
download | openvswitch-6bc3bb829c5fbcd77a1fd3ee18dbaea49b464e8f.tar.gz |
cmap: Merge CMAP_FOR_EACH_SAFE into CMAP_FOR_EACH.
There isn't any significant downside to making cmap iteration "safe" all
the time, so this drops the _SAFE variant.
Similar changes to CMAP_CURSOR_FOR_EACH and CMAP_CURSOR_FOR_EACH_CONTINUE.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Diffstat (limited to 'lib/cmap.h')
-rw-r--r-- | lib/cmap.h | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/lib/cmap.h b/lib/cmap.h index 87a1d531f..038db6c04 100644 --- a/lib/cmap.h +++ b/lib/cmap.h @@ -163,33 +163,29 @@ struct cmap_node *cmap_find_protected(const struct cmap *, uint32_t hash); * ...operate on my_node... * } * - * CMAP_FOR_EACH_SAFE variant is useful only in deallocation code already - * executing at postponed time, when it is known that the RCU grace period - * has already expired. + * CMAP_FOR_EACH is "safe" in the sense of HMAP_FOR_EACH_SAFE. That is, it is + * safe to free the current node before going on to the next iteration. Most + * of the time, though, this doesn't matter for a cmap because node + * deallocation has to be postponed until the next grace period. This means + * that this guarantee is useful only in deallocation code already executing at + * postponed time, when it is known that the RCU grace period has already + * expired. */ -#define CMAP_CURSOR_FOR_EACH(NODE, MEMBER, CURSOR, CMAP) \ - for (*(CURSOR) = cmap_cursor_start(CMAP); \ - ((CURSOR)->node \ - ? (ASSIGN_CONTAINER(NODE, (CURSOR)->node, MEMBER), true) \ - : false); \ - cmap_cursor_advance(CURSOR)) - -#define CMAP_CURSOR_FOR_EACH_SAFE(NODE, MEMBER, CURSOR, CMAP) \ - for (*(CURSOR) = cmap_cursor_start(CMAP); \ - ((CURSOR)->node \ - ? (ASSIGN_CONTAINER(NODE, (CURSOR)->node, MEMBER), \ - cmap_cursor_advance(CURSOR), \ - true) \ - : false); \ +#define CMAP_CURSOR_FOR_EACH__(NODE, CURSOR, MEMBER) \ + ((CURSOR)->node \ + ? (ASSIGN_CONTAINER(NODE, (CURSOR)->node, MEMBER), \ + cmap_cursor_advance(CURSOR), \ + true) \ + : false) + +#define CMAP_CURSOR_FOR_EACH(NODE, MEMBER, CURSOR, CMAP) \ + for (*(CURSOR) = cmap_cursor_start(CMAP); \ + CMAP_CURSOR_FOR_EACH__(NODE, CURSOR, MEMBER); \ ) -#define CMAP_CURSOR_FOR_EACH_CONTINUE(NODE, MEMBER, CURSOR) \ - for (cmap_cursor_advance(CURSOR); \ - ((CURSOR)->node \ - ? (ASSIGN_CONTAINER(NODE, (CURSOR)->node, MEMBER), true) \ - : false); \ - cmap_cursor_advance(CURSOR)) +#define CMAP_CURSOR_FOR_EACH_CONTINUE(NODE, MEMBER, CURSOR) \ + while (CMAP_CURSOR_FOR_EACH__(NODE, CURSOR, MEMBER)) struct cmap_cursor { const struct cmap_impl *impl; @@ -201,20 +197,9 @@ struct cmap_cursor { struct cmap_cursor cmap_cursor_start(const struct cmap *); void cmap_cursor_advance(struct cmap_cursor *); -#define CMAP_FOR_EACH(NODE, MEMBER, CMAP) \ - for (struct cmap_cursor cursor__ = cmap_cursor_start(CMAP); \ - (cursor__.node \ - ? (ASSIGN_CONTAINER(NODE, cursor__.node, MEMBER), true) \ - : false); \ - cmap_cursor_advance(&cursor__)) - -#define CMAP_FOR_EACH_SAFE(NODE, MEMBER, CMAP) \ +#define CMAP_FOR_EACH(NODE, MEMBER, CMAP) \ for (struct cmap_cursor cursor__ = cmap_cursor_start(CMAP); \ - (cursor__.node \ - ? (ASSIGN_CONTAINER(NODE, cursor__.node, MEMBER), \ - cmap_cursor_advance(&cursor__), \ - true) \ - : false); \ + CMAP_CURSOR_FOR_EACH__(NODE, &cursor__, MEMBER); \ ) static inline struct cmap_node *cmap_first(const struct cmap *); |