diff options
author | Mark Johnston <markj@FreeBSD.org> | 2020-07-06 21:20:57 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2020-07-06 21:20:57 +0000 |
commit | 26dd4278000890378d1660509fc68c2a03aa4fcb (patch) | |
tree | fc284143c42f950948d55df511651515791a6677 /sys/net | |
parent | d3112319ac84a151a44f5b0660c0e158c487f2ea (diff) | |
download | src-26dd4278000890378d1660509fc68c2a03aa4fcb.tar.gz src-26dd4278000890378d1660509fc68c2a03aa4fcb.zip |
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
Notes
Notes:
svn path=/head/; revision=362976
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/route/nhop_ctl.c | 13 | ||||
-rw-r--r-- | sys/net/route/shared.h | 3 |
2 files changed, 13 insertions, 3 deletions
diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index 2d74faa212ce..7787d403eb84 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -598,9 +598,18 @@ 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 diff --git a/sys/net/route/shared.h b/sys/net/route/shared.h index bca0467d891d..ce5075896c96 100644 --- a/sys/net/route/shared.h +++ b/sys/net/route/shared.h @@ -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); |