sys/libkern/idr.c
static void
idr_grow(struct idr *idp, int want)
{
	struct idr_node *newnodes;
	struct idr_node *oldnodes;
	int nf, extra;

	nf = idp->idr_count;
	do {
		/* nf has to be of the form 2^n - 1 */
		nf = 2 * nf + 1;
	} while (nf <= want);

	spin_unlock(&idp->idr_spin);
	newnodes = kmalloc(nf * sizeof(struct idr_node), M_IDR, M_WAITOK);
	spin_lock(&idp->idr_spin);

	/*
	 * We could have raced another extend while we were not holding
	 * the spinlock.
	 */
	if (idp->idr_count >= nf) {
		spin_unlock(&idp->idr_spin);
		kfree(newnodes, M_IDR);
		spin_lock(&idp->idr_spin);
		return;
	}
	/*
	 * Copy the existing ofile and ofileflags arrays
	 * and zero the new portion of each array.
	 */
	extra = nf - idp->idr_count;
	if (idp->idr_nodes != NULL)
		bcopy(idp->idr_nodes, newnodes, idp->idr_count * sizeof(struct idr_node));
	bzero(&newnodes[idp->idr_count], extra * sizeof(struct idr_node));

	oldnodes = idp->idr_nodes;
	idp->idr_nodes = newnodes;
	idp->idr_count = nf;

	if (oldnodes != NULL) {
		spin_unlock(&idp->idr_spin);
		kfree(oldnodes, M_IDR);
		spin_lock(&idp->idr_spin);
	}

	idp->idr_nexpands++;
}
/*
 * Grow the file table so it can hold through descriptor (want).
 *
 * The fdp's spinlock must be held exclusively on entry and may be held
 * exclusively on return.  The spinlock may be cycled by the routine.
 *
 * MPSAFE
 */
Grow the file table so it can hold through descriptor (want).
The fdp's spinlock must be held exclusively on entry and may be held
exclusively on return.  The spinlock may be cycled by the routine.

MPSAFE
Grow the file table so it can hold through descriptor ( want ) . The fdp ' s spinlock must be held exclusively on entry and may be held exclusively on return . The spinlock may be cycled by the routine . MPSAFE
static void
idr_grow(struct idr *idp, int want)
{
	struct idr_node *newnodes;
	struct idr_node *oldnodes;
	int nf, extra;
	nf = idp->idr_count;
	do {
		nf = 2 * nf + 1;
	} while (nf <= want);
	spin_unlock(&idp->idr_spin);
	newnodes = kmalloc(nf * sizeof(struct idr_node), M_IDR, M_WAITOK);
	spin_lock(&idp->idr_spin);
	if (idp->idr_count >= nf) {
		spin_unlock(&idp->idr_spin);
		kfree(newnodes, M_IDR);
		spin_lock(&idp->idr_spin);
		return;
	}
	extra = nf - idp->idr_count;
	if (idp->idr_nodes != NULL)
		bcopy(idp->idr_nodes, newnodes, idp->idr_count * sizeof(struct idr_node));
	bzero(&newnodes[idp->idr_count], extra * sizeof(struct idr_node));
	oldnodes = idp->idr_nodes;
	idp->idr_nodes = newnodes;
	idp->idr_count = nf;
	if (oldnodes != NULL) {
		spin_unlock(&idp->idr_spin);
		kfree(oldnodes, M_IDR);
		spin_lock(&idp->idr_spin);
	}
	idp->idr_nexpands++;
}
static void idr_grow ( struct idr * idp , int want ) { struct idr_node * newnodes ; struct idr_node * oldnodes ; int nf , extra ; nf = idp -> idr_count ; do { nf = 2 * nf + 1 ; } while ( nf <= want ) ; spin_unlock ( & idp -> idr_spin ) ; newnodes = kmalloc ( nf * sizeof ( struct idr_node ) , M_IDR , M_WAITOK ) ; spin_lock ( & idp -> idr_spin ) ; if ( idp -> idr_count >= nf ) { spin_unlock ( & idp -> idr_spin ) ; kfree ( newnodes , M_IDR ) ; spin_lock ( & idp -> idr_spin ) ; return ; } extra = nf - idp -> idr_count ; if ( idp -> idr_nodes != NULL ) bcopy ( idp -> idr_nodes , newnodes , idp -> idr_count * sizeof ( struct idr_node ) ) ; bzero ( & newnodes [ idp -> idr_count ] , extra * sizeof ( struct idr_node ) ) ; oldnodes = idp -> idr_nodes ; idp -> idr_nodes = newnodes ; idp -> idr_count = nf ; if ( oldnodes != NULL ) { spin_unlock ( & idp -> idr_spin ) ; kfree ( oldnodes , M_IDR ) ; spin_lock ( & idp -> idr_spin ) ; } idp -> idr_nexpands ++ ; }
Grow the file table so it can hold through descriptor (want).
Grow the file table so it can hold through descriptor ( want ) .
/* nf has to be of the form 2^n - 1 */ /*
	 * We could have raced another extend while we were not holding
	 * the spinlock.
	 */ /*
	 * Copy the existing ofile and ofileflags arrays
	 * and zero the new portion of each array.
	 */