pt_create, pt_destroy, pt_getblock, pt_retblock - fixed size block memory allocation
#include <sys.h>
pt_getblock() and pt_freeblock() are callable from an ISR.
Partitions support allocation and deallocation of fixed size blocks from a memory region. They are used to manage a collection of blocks of the same size with exceptionally fast allocation and deallocation. The partitions support allocation and deallocation by any thread on the same core which allows user threads to fill a buffer, pass the buffer on (using mq_send for example) and then have some other thread return the buffer to the partition.
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.
If pt_create() or pt_destroy() fails, they will return -1 and set errno. If pt_getblock() fails, it will return 0.
pt_create() will return the following errors:
pt_destroy() will return the following errors:
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.