NAME

pt_create, pt_destroy, pt_getblock, pt_retblock
- fixed size block memory allocation

SYNOPSIS

#include <sys.h>

int pt_create( size_t blocksize , int numblocks );
int pt_destroy( int ptno );
void *pt_getblock( int ptno );
void pt_freeblock( int ptno , void *block );

pt_getblock() and pt_freeblock() are callable from an ISR.

DESCRIPTION

pt_create() creates a partition from which memory can be dynamically allocated in fixed blocksize blocks. numblocks blocks will be available in the partition. If sucessfull, pt_create() returns ptno, which is a system identifier which will be used by threads to access the partition. pt_getblock() is called to get a fixed sized buffer from the partition ptno. A pointer to the buffer is returned if the call was successful. pt_freeblock() returns a fixed size buffer, pointed to by block, to the partition ptno. block must be the value from a successfull pt_getblock call. pt_destroy will delete the partition with the system identifier ptno All allocated buffers must be returned to the partition before it can be successfully deleted.

RETURN VALUES

If pt_create() or pt_destroy() fails, they will return -1 and set errno. If pt_getblock() fails, it will return 0.

ERRORS

pt_create() will return the following errors:

EINVAL
blocksize or numblocks are 0.
ENOSPC
Not enough memory to allocate the partition.
EAGAIN
All 8 partitions have been allocated.

pt_destroy() will return the following errors:

EBADID
ptno was not a valid partition.
EBUSY
ptno has outstanding blocks allocated.

NOTES

pt_create() calls kalloc(KA_PT, ...) to allocate the memory for the partition. The size passed to kalloc will contain all the overhead for the partition.

SEE ALSO

kalloc(), pool_create()




< Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2008 >