blob: 2533cadaa423faad2dc15851930d4488864a0e99 [file] [log] [blame] [edit]
// SPDX-License-Identifier: GPL-2.0+
#ifndef __MEMORY_POOL_H
#define __MEMORY_POOL_H
struct memory_pool;
/**
* Creates a new memory pool object.
*
* @pool_start - starting address of an existing contiguous memory range.
* @pool_size - size in bytes of the contiguous memory range.
* @block_size - fixed size in bytes of each allocation unit.
*
* Returns a pointer to the new memory pool or NULL on error.
*/
struct memory_pool *memory_pool_create(uintptr_t pool_start, size_t pool_size,
size_t block_size);
/**
* Destroyes a memory pool.
*
* Does nothing if @pool == NULL.
*/
void memory_pool_destroy(struct memory_pool *pool);
/**
* Allocates a buffer from the memory pool.
*
* @pool - pointer to an initialized pool.
* @align - desired buffer address alignment, zero or a power of 2.
* @bytes - desired buffer size in bytes.
*
* Returns NULL on error else buffer address.
*/
void *memory_pool_allocate(struct memory_pool *pool, size_t align,
size_t bytes);
/**
* Returns an allocated buffer to the memory pool.
*
* @pool - pointer to an initialized memory pool.
* @ptr - pointer to an previously allocated buffer.
*/
void memory_pool_deallocate(struct memory_pool *pool, void *ptr);
#endif /* __MEMORY_POOL_H */