aboutsummaryrefslogtreecommitdiff
path: root/lib/lacp.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-06-18 16:44:23 -0700
committerEthan Jackson <ethan@nicira.com>2013-06-27 18:23:39 -0700
commit91779071abffe3b6d6243378ff06a179bf39d69a (patch)
treeab319cfea600adb22792fa3a6dfb674bb3c1ece2 /lib/lacp.c
parent92cfab82fc4287aa1859ae38c596bfd03fa45bd1 (diff)
lacp: Reference count 'struct lacp'.
Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/lacp.c')
-rw-r--r--lib/lacp.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/lacp.c b/lib/lacp.c
index 8bc115dd..9daca3bd 100644
--- a/lib/lacp.c
+++ b/lib/lacp.c
@@ -100,6 +100,8 @@ struct lacp {
bool fast; /* True if using fast probe interval. */
bool negotiated; /* True if LACP negotiations were successful. */
bool update; /* True if lacp_update() needs to be called. */
+
+ int ref_cnt;
};
struct slave {
@@ -197,14 +199,31 @@ lacp_create(void)
lacp = xzalloc(sizeof *lacp);
hmap_init(&lacp->slaves);
list_push_back(&all_lacps, &lacp->node);
+ lacp->ref_cnt = 1;
+ return lacp;
+}
+
+struct lacp *
+lacp_ref(const struct lacp *lacp_)
+{
+ struct lacp *lacp = CONST_CAST(struct lacp *, lacp_);
+ if (lacp) {
+ ovs_assert(lacp->ref_cnt > 0);
+ lacp->ref_cnt++;
+ }
return lacp;
}
/* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */
void
-lacp_destroy(struct lacp *lacp)
+lacp_unref(struct lacp *lacp)
{
- if (lacp) {
+ if (!lacp) {
+ return;
+ }
+
+ ovs_assert(lacp->ref_cnt > 0);
+ if (!--lacp->ref_cnt) {
struct slave *slave, *next;
HMAP_FOR_EACH_SAFE (slave, next, node, &lacp->slaves) {