X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Flacp.c;h=cbe2259f43699722b7c86324e053fbe4baf40909;hb=c37c03826ce05e0d8262180b102923574eea01eb;hp=9eec1f962d073f500dc0dc4bc67dcc3dfd8cbdd8;hpb=428b2eddc9c47d8306252f0fc5218839d2ff017c;p=sliver-openvswitch.git diff --git a/lib/lacp.c b/lib/lacp.c index 9eec1f962..cbe2259f4 100644 --- a/lib/lacp.c +++ b/lib/lacp.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, 2012, 2013 Nicira, Inc. +/* Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ struct lacp { bool update; /* True if lacp_update() needs to be called. */ bool fallback_ab; /* True if fallback to active-backup on LACP failure. */ - atomic_int ref_cnt; + struct ovs_refcount ref_cnt; }; struct slave { @@ -216,7 +216,7 @@ lacp_create(void) OVS_EXCLUDED(mutex) lacp = xzalloc(sizeof *lacp); hmap_init(&lacp->slaves); - atomic_init(&lacp->ref_cnt, 1); + ovs_refcount_init(&lacp->ref_cnt); ovs_mutex_lock(&mutex); list_push_back(all_lacps, &lacp->node); @@ -229,9 +229,7 @@ lacp_ref(const struct lacp *lacp_) { struct lacp *lacp = CONST_CAST(struct lacp *, lacp_); if (lacp) { - int orig; - atomic_add(&lacp->ref_cnt, 1, &orig); - ovs_assert(orig > 0); + ovs_refcount_ref(&lacp->ref_cnt); } return lacp; } @@ -240,15 +238,7 @@ lacp_ref(const struct lacp *lacp_) void lacp_unref(struct lacp *lacp) OVS_EXCLUDED(mutex) { - int orig; - - if (!lacp) { - return; - } - - atomic_sub(&lacp->ref_cnt, 1, &orig); - ovs_assert(orig > 0); - if (orig == 1) { + if (lacp && ovs_refcount_unref(&lacp->ref_cnt) == 1) { struct slave *slave, *next; ovs_mutex_lock(&mutex);