FreeBSD/sys/kern/kern_lockf.c
/*
 * Allocate a vertex from the free list. Return ENOMEM if there are
 * none.
 */
Allocate a vertex from the free list. Return ENOMEM if there are
none.
Allocate a vertex from the free list . Return ENOMEM if there are none .
static struct owner_vertex *
graph_alloc_vertex(struct owner_graph *g, struct lock_owner *lo)
{
	struct owner_vertex *v;
	sx_assert(&lf_owner_graph_lock, SX_XLOCKED);
	v = malloc(sizeof(struct owner_vertex), M_LOCKF, M_WAITOK);
	if (g->g_size == g->g_space) {
		g->g_vertices = realloc(g->g_vertices,
		    2 * g->g_space * sizeof(struct owner_vertex *),
		    M_LOCKF, M_WAITOK);
		free(g->g_indexbuf, M_LOCKF);
		g->g_indexbuf = malloc(2 * g->g_space * sizeof(int),
		    M_LOCKF, M_WAITOK);
		g->g_space = 2 * g->g_space;
	}
	v->v_order = g->g_size;
	v->v_gen = g->g_gen;
	g->g_vertices[g->g_size] = v;
	g->g_size++;
	LIST_INIT(&v->v_outedges);
	LIST_INIT(&v->v_inedges);
	v->v_owner = lo;
	return (v);
}
static struct owner_vertex * graph_alloc_vertex ( struct owner_graph * g , struct lock_owner * lo ) { struct owner_vertex * v ; sx_assert ( & lf_owner_graph_lock , SX_XLOCKED ) ; v = malloc ( sizeof ( struct owner_vertex ) , M_LOCKF , M_WAITOK ) ; if ( g -> g_size == g -> g_space ) { g -> g_vertices = realloc ( g -> g_vertices , 2 * g -> g_space * sizeof ( struct owner_vertex * ) , M_LOCKF , M_WAITOK ) ; free ( g -> g_indexbuf , M_LOCKF ) ; g -> g_indexbuf = malloc ( 2 * g -> g_space * sizeof ( int ) , M_LOCKF , M_WAITOK ) ; g -> g_space = 2 * g -> g_space ; } v -> v_order = g -> g_size ; v -> v_gen = g -> g_gen ; g -> g_vertices [ g -> g_size ] = v ; g -> g_size ++ ; LIST_INIT ( & v -> v_outedges ) ; LIST_INIT ( & v -> v_inedges ) ; v -> v_owner = lo ; return ( v ) ; }
Allocate a vertex from the free list.
Allocate a vertex from the free list .