mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
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>
This commit is contained in:
@@ -111,7 +111,7 @@ mac_learning_create(unsigned int idle_time)
|
||||
ml->idle_time = normalize_idle_time(idle_time);
|
||||
ml->max_entries = MAC_DEFAULT_MAX;
|
||||
ml->need_revalidate = false;
|
||||
atomic_init(&ml->ref_cnt, 1);
|
||||
ovs_refcount_init(&ml->ref_cnt);
|
||||
ovs_rwlock_init(&ml->rwlock);
|
||||
return ml;
|
||||
}
|
||||
@@ -121,9 +121,7 @@ mac_learning_ref(const struct mac_learning *ml_)
|
||||
{
|
||||
struct mac_learning *ml = CONST_CAST(struct mac_learning *, ml_);
|
||||
if (ml) {
|
||||
int orig;
|
||||
atomic_add(&ml->ref_cnt, 1, &orig);
|
||||
ovs_assert(orig > 0);
|
||||
ovs_refcount_ref(&ml->ref_cnt);
|
||||
}
|
||||
return ml;
|
||||
}
|
||||
@@ -132,15 +130,7 @@ mac_learning_ref(const struct mac_learning *ml_)
|
||||
void
|
||||
mac_learning_unref(struct mac_learning *ml)
|
||||
{
|
||||
int orig;
|
||||
|
||||
if (!ml) {
|
||||
return;
|
||||
}
|
||||
|
||||
atomic_sub(&ml->ref_cnt, 1, &orig);
|
||||
ovs_assert(orig > 0);
|
||||
if (orig == 1) {
|
||||
if (ml && ovs_refcount_unref(&ml->ref_cnt) == 1) {
|
||||
struct mac_entry *e, *next;
|
||||
|
||||
HMAP_FOR_EACH_SAFE (e, next, hmap_node, &ml->table) {
|
||||
@@ -151,7 +141,7 @@ mac_learning_unref(struct mac_learning *ml)
|
||||
|
||||
bitmap_free(ml->flood_vlans);
|
||||
ovs_rwlock_destroy(&ml->rwlock);
|
||||
atomic_destroy(&ml->ref_cnt);
|
||||
ovs_refcount_destroy(&ml->ref_cnt);
|
||||
free(ml);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user