Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pppoe: disc: document who holds references to the net object #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions accel-pppd/ctrl/pppoe/disc.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct disc_net *init_net(const struct ap_net *net)
n->hnd.fd = sock;
n->hnd.read = disc_read;
n->net = net;
/* Initial self-reference, to be released at net shutdown */
n->refs = 1;

triton_context_register(&n->ctx, NULL);
Expand Down Expand Up @@ -182,6 +183,7 @@ int pppoe_disc_start(struct pppoe_serv_t *serv)
rb_link_node(&serv->node, parent, p);
rb_insert_color(&serv->node, &t->root);

/* Register a reference to the net object */
__sync_add_and_fetch(&net->refs, 1);

pthread_mutex_unlock(&t->lock);
Expand All @@ -198,6 +200,7 @@ void pppoe_disc_stop(struct pppoe_serv_t *serv)
rb_erase(&serv->node, &t->root);
pthread_mutex_unlock(&t->lock);

/* Release the serv reference to the net object */
if (__sync_sub_and_fetch(&n->refs, 1) == 0)
free_net(n);
}
Expand Down Expand Up @@ -280,6 +283,7 @@ static void disc_stop(struct disc_net *net)
pthread_mutex_unlock(&t->lock);
}

/* Release the initial reference. */
if (__sync_sub_and_fetch(&net->refs, 1) == 0)
free_net(net);
}
Expand Down