Date: Mon, 6 Jul 2020 21:20:58 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362976 - head/sys/net/route Message-ID: <202007062120.066LKwdV063632@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Mon Jul 6 21:20:57 2020 New Revision: 362976 URL: https://svnweb.freebsd.org/changeset/base/362976 Log: Split nhop_ref_object(). Now nhop_ref_object() unconditionally acquires a reference, and the new nhop_try_ref_object() uses refcount_acquire_if_not_zero() to conditionally acquire a reference. Since the former is cheaper, use it when we know that the initial counter value is non-zero. No functional change intended. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D25535 Modified: head/sys/net/route/nhop_ctl.c head/sys/net/route/shared.h Modified: head/sys/net/route/nhop_ctl.c ============================================================================== --- head/sys/net/route/nhop_ctl.c Mon Jul 6 20:23:14 2020 (r362975) +++ head/sys/net/route/nhop_ctl.c Mon Jul 6 21:20:57 2020 (r362976) @@ -598,10 +598,19 @@ destroy_nhop_epoch(epoch_context_t ctx) destroy_nhop(nh_priv); } -int +void nhop_ref_object(struct nhop_object *nh) { + u_int old; + old = refcount_acquire(&nh->nh_priv->nh_refcnt); + KASSERT(old > 0, ("%s: nhop object %p has 0 refs", __func__, nh)); +} + +int +nhop_try_ref_object(struct nhop_object *nh) +{ + return (refcount_acquire_if_not_zero(&nh->nh_priv->nh_refcnt)); } @@ -654,7 +663,7 @@ int nhop_ref_any(struct nhop_object *nh) { - return (nhop_ref_object(nh)); + return (nhop_try_ref_object(nh)); } void Modified: head/sys/net/route/shared.h ============================================================================== --- head/sys/net/route/shared.h Mon Jul 6 20:23:14 2020 (r362975) +++ head/sys/net/route/shared.h Mon Jul 6 21:20:57 2020 (r362976) @@ -51,7 +51,8 @@ struct rib_head; void nhops_init(void); int nhops_init_rib(struct rib_head *rh); void nhops_destroy_rib(struct rib_head *rh); -int nhop_ref_object(struct nhop_object *nh); +void nhop_ref_object(struct nhop_object *nh); +int nhop_try_ref_object(struct nhop_object *nh); int nhop_ref_any(struct nhop_object *nh); void nhop_free_any(struct nhop_object *nh);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007062120.066LKwdV063632>