Replace hand-rolled unrefs if > 1 with refcount_release_if_not_last
Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
f07c942dd8
commit
6ff4688b09
@ -4023,13 +4023,11 @@ prison_racct_free_locked(struct prison_racct *prr)
|
|||||||
void
|
void
|
||||||
prison_racct_free(struct prison_racct *prr)
|
prison_racct_free(struct prison_racct *prr)
|
||||||
{
|
{
|
||||||
int old;
|
|
||||||
|
|
||||||
ASSERT_RACCT_ENABLED();
|
ASSERT_RACCT_ENABLED();
|
||||||
sx_assert(&allprison_lock, SA_UNLOCKED);
|
sx_assert(&allprison_lock, SA_UNLOCKED);
|
||||||
|
|
||||||
old = prr->prr_refcount;
|
if (refcount_release_if_not_last(&prr->prr_refcount))
|
||||||
if (old > 1 && atomic_cmpset_int(&prr->prr_refcount, old, old - 1))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sx_xlock(&allprison_lock);
|
sx_xlock(&allprison_lock);
|
||||||
|
@ -84,10 +84,8 @@ loginclass_hold(struct loginclass *lc)
|
|||||||
void
|
void
|
||||||
loginclass_free(struct loginclass *lc)
|
loginclass_free(struct loginclass *lc)
|
||||||
{
|
{
|
||||||
int old;
|
|
||||||
|
|
||||||
old = lc->lc_refcount;
|
if (refcount_release_if_not_last(&lc->lc_refcount))
|
||||||
if (old > 1 && atomic_cmpset_int(&lc->lc_refcount, old, old - 1))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rw_wlock(&loginclasses_lock);
|
rw_wlock(&loginclasses_lock);
|
||||||
|
@ -1323,14 +1323,10 @@ uihold(struct uidinfo *uip)
|
|||||||
void
|
void
|
||||||
uifree(struct uidinfo *uip)
|
uifree(struct uidinfo *uip)
|
||||||
{
|
{
|
||||||
int old;
|
|
||||||
|
|
||||||
/* Prepare for optimal case. */
|
if (refcount_release_if_not_last(&uip->ui_ref))
|
||||||
old = uip->ui_ref;
|
|
||||||
if (old > 1 && atomic_cmpset_int(&uip->ui_ref, old, old - 1))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Prepare for suboptimal case. */
|
|
||||||
rw_wlock(&uihashtbl_lock);
|
rw_wlock(&uihashtbl_lock);
|
||||||
if (refcount_release(&uip->ui_ref) == 0) {
|
if (refcount_release(&uip->ui_ref) == 0) {
|
||||||
rw_wunlock(&uihashtbl_lock);
|
rw_wunlock(&uihashtbl_lock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user