diff options
author | glebius <glebius@FreeBSD.org> | 2011-07-04 07:03:44 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2011-07-04 07:03:44 +0000 |
commit | ffb5cf471446f18c2ed162926526b1930bfa572b (patch) | |
tree | c636f50c30142b8d254242bb07d18e28e30a26eb /sys/netgraph/ng_base.c | |
parent | 766eac763608b17c9277e49469f5f329f4a16332 (diff) | |
download | FreeBSD-src-ffb5cf471446f18c2ed162926526b1930bfa572b.zip FreeBSD-src-ffb5cf471446f18c2ed162926526b1930bfa572b.tar.gz |
- Use refcount(9) API to manage node and hook refcounting.
- Make ng_unref_node() void, since caller shouldn't be
interested in whether node is valid after call or not,
since it can't be guaranteed to be valid. [1]
Ok from: julian [1]
Diffstat (limited to 'sys/netgraph/ng_base.c')
-rw-r--r-- | sys/netgraph/ng_base.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index f67f247f..0918193 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -772,18 +772,14 @@ ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3) * Remove a reference to the node, possibly the last. * deadnode always acts as it it were the last. */ -int +void ng_unref_node(node_p node) { - int v; - - if (node == &ng_deadnode) { - return (0); - } - v = atomic_fetchadd_int(&node->nd_refs, -1); + if (node == &ng_deadnode) + return; - if (v == 1) { /* we were the last */ + if (refcount_release(&node->nd_refs)) { /* we were the last */ mtx_lock(&ng_namehash_mtx); node->nd_type->refs--; /* XXX maybe should get types lock? */ @@ -797,7 +793,6 @@ ng_unref_node(node_p node) mtx_destroy(&node->nd_input_queue.q_mtx); NG_FREE_NODE(node); } - return (v - 1); } /************************************************************************ @@ -963,15 +958,11 @@ ng_unname(node_p node) void ng_unref_hook(hook_p hook) { - int v; - if (hook == &ng_deadhook) { + if (hook == &ng_deadhook) return; - } - - v = atomic_fetchadd_int(&hook->hk_refs, -1); - if (v == 1) { /* we were the last */ + if (refcount_release(&hook->hk_refs)) { /* we were the last */ if (_NG_HOOK_NODE(hook)) /* it'll probably be ng_deadnode */ _NG_NODE_UNREF((_NG_HOOK_NODE(hook))); NG_FREE_HOOK(hook); |