Date: Mon, 4 Jul 2011 07:03:44 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r223754 - head/sys/netgraph Message-ID: <201107040703.p6473inv058324@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Mon Jul 4 07:03:44 2011 New Revision: 223754 URL: http://svn.freebsd.org/changeset/base/223754 Log: - 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] Modified: head/sys/netgraph/netgraph.h head/sys/netgraph/ng_base.c Modified: head/sys/netgraph/netgraph.h ============================================================================== --- head/sys/netgraph/netgraph.h Mon Jul 4 05:47:48 2011 (r223753) +++ head/sys/netgraph/netgraph.h Mon Jul 4 07:03:44 2011 (r223754) @@ -53,6 +53,7 @@ #include <sys/malloc.h> #include <sys/module.h> #include <sys/mutex.h> +#include <sys/refcount.h> #ifdef HAVE_KERNEL_OPTION_HEADERS #include "opt_netgraph.h" @@ -137,7 +138,7 @@ struct ng_hook { * If you can't do it with these you probably shouldn;t be doing it. */ void ng_unref_hook(hook_p hook); /* don't move this */ -#define _NG_HOOK_REF(hook) atomic_add_int(&(hook)->hk_refs, 1) +#define _NG_HOOK_REF(hook) refcount_acquire(&(hook)->hk_refs) #define _NG_HOOK_NAME(hook) ((hook)->hk_name) #define _NG_HOOK_UNREF(hook) ng_unref_hook(hook) #define _NG_HOOK_SET_PRIVATE(hook, val) do {(hook)->hk_private = val;} while (0) @@ -396,11 +397,11 @@ struct ng_node { * Public methods for nodes. * If you can't do it with these you probably shouldn't be doing it. */ -int ng_unref_node(node_p node); /* don't move this */ +void ng_unref_node(node_p node); /* don't move this */ #define _NG_NODE_NAME(node) ((node)->nd_name + 0) #define _NG_NODE_HAS_NAME(node) ((node)->nd_name[0] + 0) #define _NG_NODE_ID(node) ((node)->nd_ID + 0) -#define _NG_NODE_REF(node) atomic_add_int(&(node)->nd_refs, 1) +#define _NG_NODE_REF(node) refcount_acquire(&(node)->nd_refs) #define _NG_NODE_UNREF(node) ng_unref_node(node) #define _NG_NODE_SET_PRIVATE(node, val) do {(node)->nd_private = val;} while (0) #define _NG_NODE_PRIVATE(node) ((node)->nd_private) Modified: head/sys/netgraph/ng_base.c ============================================================================== --- head/sys/netgraph/ng_base.c Mon Jul 4 05:47:48 2011 (r223753) +++ head/sys/netgraph/ng_base.c Mon Jul 4 07:03:44 2011 (r223754) @@ -772,18 +772,14 @@ ng_rmnode(node_p node, hook_p dummy1, vo * 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107040703.p6473inv058324>