summaryrefslogtreecommitdiff
path: root/ofproto/netflow.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-12-27 19:39:24 -0800
committerBen Pfaff <blp@nicira.com>2014-01-08 17:13:30 -0800
commit37bec3d330ed7f72b6a867728c538b49e5727dc7 (patch)
treebbb899adc71b41c32853a1b04ae435832b3d2607 /ofproto/netflow.c
parentc5f81b20da9bbf0ac406a88718597a4e84729a98 (diff)
downloadopenvswitch-37bec3d330ed7f72b6a867728c538b49e5727dc7.tar.gz
ovs-atomic: Introduce a new 'struct ovs_refcount'.
This is a thin wrapper around an atomic_uint. It is useful anyhow because each ovs_refcount_ref() or ovs_refcount_unref() call saves a few lines of code. This commit also changes all the potential direct users over to use the new data structure. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'ofproto/netflow.c')
-rw-r--r--ofproto/netflow.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/ofproto/netflow.c b/ofproto/netflow.c
index 3aa0630bf..8259cede3 100644
--- a/ofproto/netflow.c
+++ b/ofproto/netflow.c
@@ -53,7 +53,7 @@ struct netflow {
struct hmap flows; /* Contains 'netflow_flows'. */
- atomic_int ref_cnt;
+ struct ovs_refcount ref_cnt;
};
struct netflow_flow {
@@ -405,7 +405,7 @@ netflow_create(void)
nf->add_id_to_iface = false;
nf->netflow_cnt = 0;
hmap_init(&nf->flows);
- atomic_init(&nf->ref_cnt, 1);
+ ovs_refcount_init(&nf->ref_cnt);
ofpbuf_init(&nf->packet, 1500);
atomic_add(&netflow_count, 1, &junk);
return nf;
@@ -416,9 +416,7 @@ netflow_ref(const struct netflow *nf_)
{
struct netflow *nf = CONST_CAST(struct netflow *, nf_);
if (nf) {
- int orig;
- atomic_add(&nf->ref_cnt, 1, &orig);
- ovs_assert(orig > 0);
+ ovs_refcount_ref(&nf->ref_cnt);
}
return nf;
}
@@ -426,19 +424,13 @@ netflow_ref(const struct netflow *nf_)
void
netflow_unref(struct netflow *nf)
{
- int orig;
-
- if (!nf) {
- return;
- }
+ if (nf && ovs_refcount_unref(&nf->ref_cnt) == 1) {
+ int orig;
- atomic_sub(&nf->ref_cnt, 1, &orig);
- ovs_assert(orig > 0);
- if (orig == 1) {
atomic_sub(&netflow_count, 1, &orig);
collectors_destroy(nf->collectors);
ofpbuf_uninit(&nf->packet);
- atomic_destroy(&nf->ref_cnt);
+ ovs_refcount_destroy(&nf->ref_cnt);
free(nf);
}
}