[ovs-discuss] [PATCH 02/20] shash: Introduce new macros SHASH_FOR_EACH, SHASH_FOR_EACH_SAFE.
Ben Pfaff
blp at nicira.com
Fri Jul 24 21:19:45 UTC 2009
This is both more convenient and cleaner than using HMAP_FOR_EACH(_SAFE)
directly.
---
lib/shash.c | 2 +-
lib/shash.h | 7 +++++++
lib/unixctl.c | 2 +-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/shash.c b/lib/shash.c
index 7662d2e..77c493f 100644
--- a/lib/shash.c
+++ b/lib/shash.c
@@ -44,7 +44,7 @@ shash_clear(struct shash *sh)
{
struct shash_node *node, *next;
- HMAP_FOR_EACH_SAFE (node, next, struct shash_node, node, &sh->map) {
+ SHASH_FOR_EACH_SAFE (node, next, sh) {
hmap_remove(&sh->map, &node->node);
free(node->name);
free(node);
diff --git a/lib/shash.h b/lib/shash.h
index 72d8302..5794a20 100644
--- a/lib/shash.h
+++ b/lib/shash.h
@@ -31,6 +31,13 @@ struct shash {
#define SHASH_INITIALIZER(SHASH) { HMAP_INITIALIZER(&(SHASH)->map) }
+#define SHASH_FOR_EACH(SHASH_NODE, SHASH) \
+ HMAP_FOR_EACH (SHASH_NODE, struct shash_node, node, &(SHASH)->map)
+
+#define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH) \
+ HMAP_FOR_EACH_SAFE (SHASH_NODE, NEXT, struct shash_node, node, \
+ &(SHASH)->map)
+
void shash_init(struct shash *);
void shash_destroy(struct shash *);
void shash_clear(struct shash *);
diff --git a/lib/unixctl.c b/lib/unixctl.c
index 526c3fe..17bd6cb 100644
--- a/lib/unixctl.c
+++ b/lib/unixctl.c
@@ -82,7 +82,7 @@ unixctl_help(struct unixctl_conn *conn, const char *args UNUSED)
struct shash_node *node;
ds_put_cstr(&ds, "The available commands are:\n");
- HMAP_FOR_EACH (node, struct shash_node, node, &commands.map) {
+ SHASH_FOR_EACH (node, &commands) {
ds_put_format(&ds, "\t%s\n", node->name);
}
unixctl_command_reply(conn, 214, ds_cstr(&ds));
--
1.6.3.3
More information about the discuss
mailing list