[ovs-dev] [xlate v1 07/18] mac-learning: Reference count 'struct mac_learning".
Ethan Jackson
ethan at nicira.com
Tue Jun 25 01:59:21 UTC 2013
Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
lib/learning-switch.c | 2 +-
lib/mac-learning.c | 23 ++++++++++++++++++++---
lib/mac-learning.h | 4 +++-
ofproto/ofproto-dpif.c | 2 +-
4 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index 426cb37..f2b3319 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -237,7 +237,7 @@ lswitch_destroy(struct lswitch *sw)
free(node);
}
shash_destroy(&sw->queue_names);
- mac_learning_destroy(sw->ml);
+ mac_learning_unref(sw->ml);
rconn_packet_counter_destroy(sw->queued);
free(sw);
}
diff --git a/lib/mac-learning.c b/lib/mac-learning.c
index f9b3171..ca0ccb8 100644
--- a/lib/mac-learning.c
+++ b/lib/mac-learning.c
@@ -124,14 +124,31 @@ mac_learning_create(unsigned int idle_time)
ml->idle_time = normalize_idle_time(idle_time);
ml->max_entries = MAC_DEFAULT_MAX;
tag_set_init(&ml->tags);
+ ml->ref_cnt = 1;
return ml;
}
-/* Destroys MAC learning table 'ml'. */
-void
-mac_learning_destroy(struct mac_learning *ml)
+struct mac_learning *
+mac_learning_ref(const struct mac_learning *ml_)
{
+ struct mac_learning *ml = CONST_CAST(struct mac_learning *, ml_);
if (ml) {
+ ovs_assert(ml->ref_cnt > 0);
+ ml->ref_cnt++;
+ }
+ return ml;
+}
+
+/* Unreferences (and possibly destroys) MAC learning table 'ml'. */
+void
+mac_learning_unref(struct mac_learning *ml)
+{
+ if (!ml) {
+ return;
+ }
+
+ ovs_assert(ml->ref_cnt > 0);
+ if (!--ml->ref_cnt) {
struct mac_entry *e, *next;
HMAP_FOR_EACH_SAFE (e, next, hmap_node, &ml->table) {
diff --git a/lib/mac-learning.h b/lib/mac-learning.h
index 9feca00..06e99f3 100644
--- a/lib/mac-learning.h
+++ b/lib/mac-learning.h
@@ -86,11 +86,13 @@ struct mac_learning {
unsigned int idle_time; /* Max age before deleting an entry. */
size_t max_entries; /* Max number of learned MACs. */
struct tag_set tags; /* Tags which have changed. */
+ int ref_cnt;
};
/* Basics. */
struct mac_learning *mac_learning_create(unsigned int idle_time);
-void mac_learning_destroy(struct mac_learning *);
+struct mac_learning *mac_learning_ref(const struct mac_learning *);
+void mac_learning_unref(struct mac_learning *);
void mac_learning_run(struct mac_learning *, struct tag_set *);
void mac_learning_wait(struct mac_learning *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index c4b359b..9ac60be 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1187,7 +1187,7 @@ destruct(struct ofproto *ofproto_)
netflow_destroy(ofproto->netflow);
dpif_sflow_destroy(ofproto->sflow);
hmap_destroy(&ofproto->bundles);
- mac_learning_destroy(ofproto->ml);
+ mac_learning_unref(ofproto->ml);
classifier_destroy(&ofproto->facets);
--
1.7.9.5
More information about the dev
mailing list