/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident "$Header: genalloc.h 1.3 89/08/07 $"

#ifndef	_SYS_GENALLOC_H_

/*
 * genalloc.h
 *	Generic fixed-size kernel memory allocator.
 */

/* $Log:	genalloc.h,v $
 */

/*
 *
 * The genalloc routines provide kernel programmers with a simple memory
 * management interface which is generic enough to be reused in a number
 * of situations.  The allocator only manages objects which are of
 * fixed size (the instantiation size is set when the allocator is
 * initialized).  The allocator also provides the capability of growing
 * the freelist of objects when it runs out.
 *
 * These qualities make genalloc superior to using the rmap hooks.  The
 * rmap routines allow for variable-size allocations and coalescing the
 * map upon freeing.  However, since the objects which genalloc manages
 * are fixed size, the overhead required for rmap is not needed.  Also,
 * since genalloc() provides for growing the total number of allocatable
 * objects, genalloc is a good match for routines which don't know
 * a priori how many objects they will need and can't tolerate waiting
 * for them;  growing rmap in this way is "hard".
 *
 * If the heap is discovered to be a better implementation, uses of
 * genalloc can be easily mapped into calls to kmem_alloc and genalloc
 * can go away.
 */

/*
 * this structure is passed to all of the genalloc
 * hooks as an instantiation of the allocator.
 */
struct genallocator {
	lock_t	ga_mutex;		/* exclusive use of ga_free */
	sema_t	ga_sema;		/* sync point when ga_free is empty */
	caddr_t	ga_free;		/* freelist (singly linked) */
	int	ga_size;		/* instantiation size */
	int	ga_alloc_incr;		/* how much to grow ga_free by */
	caddr_t	(*ga_allocator)();	/* what to call when ga_free is empty */
};

extern	caddr_t	genalloc();

#define	_SYS_GENALLOC_H_
#endif	/* _SYS_GENALLOC_H_ */
