From 63e60b866ffee6895e1772da2c48591ab2767aa7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 28 Jan 2010 14:12:56 -0800 Subject: [PATCH] hmap: Rename hmap_moved() to hmap_node_moved(). This prepares for adding a new function that deals with a "struct hmap" moving, as opposed to a "struct hmap_node". Since there was only a single call to this in the whole tree, and its caller didn't have any callers of its own at all, also move this function from hmap.h to hmap.c. --- lib/classifier.c | 5 +++-- lib/hmap.c | 16 +++++++++++++++- lib/hmap.h | 18 ++---------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index 94c838022..f4280ef0c 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,7 +102,8 @@ cls_rule_moved(struct classifier *cls, struct cls_rule *old, if (new->wc.wildcards) { list_moved(&new->node.list); } else { - hmap_moved(&cls->exact_table, &old->node.hmap, &new->node.hmap); + hmap_node_moved(&cls->exact_table, + &old->node.hmap, &new->node.hmap); } } } diff --git a/lib/hmap.c b/lib/hmap.c index f75fc0712..d66cf271a 100644 --- a/lib/hmap.c +++ b/lib/hmap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,3 +143,17 @@ hmap_reserve(struct hmap *hmap, size_t n) resize(hmap, new_mask); } } + +/* Adjusts 'hmap' to compensate for 'old_node' having moved position in memory + * to 'node' (e.g. due to realloc()). */ +void +hmap_node_moved(struct hmap *hmap, + struct hmap_node *old_node, struct hmap_node *node) +{ + struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask]; + while (*bucket != old_node) { + bucket = &(*bucket)->next; + } + *bucket = node; +} + diff --git a/lib/hmap.h b/lib/hmap.h index c78dddaca..9bb3e5fd9 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,8 +79,7 @@ static inline void hmap_insert_fast(struct hmap *, struct hmap_node *, size_t hash); static inline void hmap_insert(struct hmap *, struct hmap_node *, size_t hash); static inline void hmap_remove(struct hmap *, struct hmap_node *); -static inline void hmap_moved(struct hmap *, - struct hmap_node *, struct hmap_node *); +void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node *); static inline void hmap_replace(struct hmap *, const struct hmap_node *old, struct hmap_node *new); @@ -207,19 +206,6 @@ hmap_remove(struct hmap *hmap, struct hmap_node *node) hmap->n--; } -/* Adjusts 'hmap' to compensate for 'old_node' having moved position in memory - * to 'node' (e.g. due to realloc()). */ -static inline void -hmap_moved(struct hmap *hmap, - struct hmap_node *old_node, struct hmap_node *node) -{ - struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask]; - while (*bucket != old_node) { - bucket = &(*bucket)->next; - } - *bucket = node; -} - /* Puts 'new' in the position in 'hmap' currently occupied by 'old'. The 'new' * node must hash to the same value as 'old'. The client is responsible for * ensuring that the replacement does not violate any client-imposed -- 2.43.0