Sound Open Firmware
Loading...
Searching...
No Matches
objpool.h File Reference
Include dependency graph for objpool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  objpool_head

Typedefs

typedef bool(* objpool_iterate_cb) (void *data, void *arg)

Functions

void * objpool_alloc (struct objpool_head *head, size_t size, uint32_t flags)
 Allocate memory tracked as part of an object pool.
int objpool_free (struct objpool_head *head, void *data)
 Return a block to the object pool.
void objpool_prune (struct objpool_head *head)
 Free all of the object pool memory.
int objpool_iterate (struct objpool_head *head, objpool_iterate_cb cb, void *arg)
 Iterate over object pool entries until stopped.

Typedef Documentation

◆ objpool_iterate_cb

typedef bool(* objpool_iterate_cb) (void *data, void *arg)

Function Documentation

◆ objpool_alloc()

void * objpool_alloc ( struct objpool_head * head,
size_t size,
uint32_t flags )

Allocate memory tracked as part of an object pool.

Parameters
headPointer to the object pool head.
sizeSize in bytes of memory blocks to allocate.
flagsMemory allocation flags.
Returns
a pointer to the allocated memory on success, NULL on failure.

Allocate a memory block of size bytes. size is used upon the first invocation to allocate memory on the heap, all consequent allocations with the same head must use the same size value. First allocation with an empty head allocates 2 blocks. After both blocks are taken and a third one is requested, the next call allocates 4 blocks, then 8, 16 and 32. After that 32 blocks are allocated every time. Note, that by design allocated blocks are never freed. See more below. TODO: flags are currently only used when allocating new object sets. Should add a check that they're consistent with already allocated objects.

◆ objpool_free()

int objpool_free ( struct objpool_head * head,
void * data )

Return a block to the object pool.

Parameters
headPointer to the object pool head.
dataPointer to the object to return (can be NULL)
Returns
0 on success or a negative error code.

Return a block to the object pool. Memory is never freed by design, unused blocks are kept in the object pool for future re-use.

◆ objpool_iterate()

int objpool_iterate ( struct objpool_head * head,
objpool_iterate_cb cb,
void * arg )

Iterate over object pool entries until stopped.

Parameters
headPointer to the object pool head.
cbCallback function
argCallback function argument
Returns
0 on success or a negative error code.

Call the callback function for each entry in the pool, until it returns true. If the callback never returns true, return an error.

◆ objpool_prune()

void objpool_prune ( struct objpool_head * head)

Free all of the object pool memory.

Parameters
headPointer to the object pool head.