FreeBSD/sys/dev/cxgb/ulp/tom/cxgb_l2t.c
/*
 * Allocate a free L2T entry.  Must be called with l2t_data.lock held.
 */
Allocate a free L2T entry.  Must be called with l2t_data.lock held.
Allocate a free L2T entry . Must be called with l2t_data . lock held .
static struct l2t_entry *
alloc_l2e(struct l2t_data *d)
{
	struct l2t_entry *end, *e, **p;
	rw_assert(&d->lock, RA_WLOCKED);
	if (!atomic_load_acq_int(&d->nfree))
		return (NULL);
	for (e = d->rover, end = &d->l2tab[d->nentries]; e != end; ++e) {
		if (atomic_load_acq_int(&e->refcnt) == 0)
			goto found;
	}
	for (e = &d->l2tab[1]; atomic_load_acq_int(&e->refcnt); ++e)
		continue;
found:
	d->rover = e + 1;
	atomic_add_int(&d->nfree, -1);
	if (e->state != L2T_STATE_UNUSED) {
		int hash = arp_hash(e->addr, e->ifp->if_index, d);
		for (p = &d->l2tab[hash].first; *p; p = &(*p)->next) {
			if (*p == e) {
				*p = e->next;
				break;
			}
		}
		e->state = L2T_STATE_UNUSED;
	}
	return (e);
}
static struct l2t_entry * alloc_l2e ( struct l2t_data * d ) { struct l2t_entry * end , * e , * * p ; rw_assert ( & d -> lock , RA_WLOCKED ) ; if ( ! atomic_load_acq_int ( & d -> nfree ) ) return ( NULL ) ; for ( e = d -> rover , end = & d -> l2tab [ d -> nentries ] ; e != end ; ++ e ) { if ( atomic_load_acq_int ( & e -> refcnt ) == 0 ) goto found ; } for ( e = & d -> l2tab [ 1 ] ; atomic_load_acq_int ( & e -> refcnt ) ; ++ e ) continue ; found : d -> rover = e + 1 ; atomic_add_int ( & d -> nfree , -1 ) ; if ( e -> state != L2T_STATE_UNUSED ) { int hash = arp_hash ( e -> addr , e -> ifp -> if_index , d ) ; for ( p = & d -> l2tab [ hash ] . first ; * p ; p = & ( * p ) -> next ) { if ( * p == e ) { * p = e -> next ; break ; } } e -> state = L2T_STATE_UNUSED ; } return ( e ) ; }
Allocate a free L2T entry.
Allocate a free L2T entry .
/* there's definitely a free entry */ /*
	 * The entry we found may be an inactive entry that is
	 * presently in the hash table.  We need to remove it.
	 */