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;
}
{
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;
}
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) {
bitmap_free(ml->flood_vlans);
ovs_rwlock_destroy(&ml->rwlock);
- atomic_destroy(&ml->ref_cnt);
+ ovs_refcount_destroy(&ml->ref_cnt);
free(ml);
}
}