From 813a8dd336d74465a27c05cfda124e2c91408a81 Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Thu, 6 Mar 2014 17:20:25 -0800 Subject: [PATCH] mirror: Use 'struct ref_count' for refcounting. Signed-off-by: Joe Stringer Signed-off-by: Ben Pfaff --- ofproto/ofproto-dpif-mirror.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ofproto/ofproto-dpif-mirror.c b/ofproto/ofproto-dpif-mirror.c index 99172dd55..fcc775890 100644 --- a/ofproto/ofproto-dpif-mirror.c +++ b/ofproto/ofproto-dpif-mirror.c @@ -36,7 +36,7 @@ struct mbridge { bool need_revalidate; bool has_mirrors; - int ref_cnt; + struct ovs_refcount ref_cnt; }; struct mbundle { @@ -82,7 +82,7 @@ mbridge_create(void) struct mbridge *mbridge; mbridge = xzalloc(sizeof *mbridge); - mbridge->ref_cnt = 1; + ovs_refcount_init(&mbridge->ref_cnt); hmap_init(&mbridge->mbundles); return mbridge; @@ -93,8 +93,7 @@ mbridge_ref(const struct mbridge *mbridge_) { struct mbridge *mbridge = CONST_CAST(struct mbridge *, mbridge_); if (mbridge) { - ovs_assert(mbridge->ref_cnt > 0); - mbridge->ref_cnt++; + ovs_refcount_ref(&mbridge->ref_cnt); } return mbridge; } @@ -109,23 +108,20 @@ mbridge_unref(struct mbridge *mbridge) return; } - ovs_assert(mbridge->ref_cnt > 0); - if (--mbridge->ref_cnt) { - return; - } + if (ovs_refcount_unref(&mbridge->ref_cnt) == 1) { + for (i = 0; i < MAX_MIRRORS; i++) { + if (mbridge->mirrors[i]) { + mirror_destroy(mbridge, mbridge->mirrors[i]->aux); + } + } - for (i = 0; i < MAX_MIRRORS; i++) { - if (mbridge->mirrors[i]) { - mirror_destroy(mbridge, mbridge->mirrors[i]->aux); + HMAP_FOR_EACH_SAFE (mbundle, next, hmap_node, &mbridge->mbundles) { + mbridge_unregister_bundle(mbridge, mbundle->ofbundle); } - } - HMAP_FOR_EACH_SAFE (mbundle, next, hmap_node, &mbridge->mbundles) { - mbridge_unregister_bundle(mbridge, mbundle->ofbundle); + hmap_destroy(&mbridge->mbundles); + free(mbridge); } - - hmap_destroy(&mbridge->mbundles); - free(mbridge); } bool -- 2.43.0