sys/kern/kern_refcount.c
void
_refcount_wait(volatile u_int *countp, const char *wstr)
{
	u_int n;
	int loops = 0;
	int threshold = 5;

	for (;;) {
		n = *countp;
		cpu_ccfence();
		if (n == 0)
			break;
		if (loops > threshold) {
			kprintf("refcount_wait %s long wait\n", wstr);
			loops = 0;
		}
		KKASSERT(n != REFCNTF_WAITING);	/* impossible state */
		tsleep_interlock(countp, 0);
		if (atomic_cmpset_int(countp, n, n | REFCNTF_WAITING))
			tsleep(countp, PINTERLOCKED, wstr, hz*10);
		loops++;
	}
}
/*
 * Helper function to wait for a reference count to become zero.
 * We set REFCNTF_WAITING and sleep if the reference count is not zero.
 *
 * In the case where REFCNTF_WAITING is already set the atomic op validates
 * that it is still set after the tsleep_interlock() call.
 *
 * Users of this waiting API must use refcount_release_wakeup() to release
 * refs instead of refcount_release().  refcount_release() will not wake
 * up waiters.
 */
Helper function to wait for a reference count to become zero.
We set REFCNTF_WAITING and sleep if the reference count is not zero.

In the case where REFCNTF_WAITING is already set the atomic op validates
that it is still set after the tsleep_interlock() call.

Users of this waiting API must use refcount_release_wakeup() to release
refs instead of refcount_release().  refcount_release() will not wake
up waiters.
Helper function to wait for a reference count to become zero . We set REFCNTF_WAITING and sleep if the reference count is not zero . In the case where REFCNTF_WAITING is already set the atomic op validates that it is still set after the tsleep_interlock () call . Users of this waiting API must use refcount_release_wakeup () to release refs instead of refcount_release () . refcount_release () will not wake up waiters .
void
_refcount_wait(volatile u_int *countp, const char *wstr)
{
	u_int n;
	int loops = 0;
	int threshold = 5;
	for (;;) {
		n = *countp;
		cpu_ccfence();
		if (n == 0)
			break;
		if (loops > threshold) {
			kprintf("refcount_wait %s long wait\n", wstr);
			loops = 0;
		}
		KKASSERT(n != REFCNTF_WAITING);	
		tsleep_interlock(countp, 0);
		if (atomic_cmpset_int(countp, n, n | REFCNTF_WAITING))
			tsleep(countp, PINTERLOCKED, wstr, hz*10);
		loops++;
	}
}
void _refcount_wait ( volatile u_int * countp , const char * wstr ) { u_int n ; int loops = 0 ; int threshold = 5 ; for ( ; ; ) { n = * countp ; cpu_ccfence ( ) ; if ( n == 0 ) break ; if ( loops > threshold ) { kprintf ( " \n " , wstr ) ; loops = 0 ; } KKASSERT ( n != REFCNTF_WAITING ) ; tsleep_interlock ( countp , 0 ) ; if ( atomic_cmpset_int ( countp , n , n | REFCNTF_WAITING ) ) tsleep ( countp , PINTERLOCKED , wstr , hz * 10 ) ; loops ++ ; } }
Helper function to wait for a reference count to become zero.
Helper function to wait for a reference count to become zero .
/* impossible state */