10#ifndef STK_C_MEMORY_H_
11#define STK_C_MEMORY_H_
73#ifndef STK_C_BLOCKPOOL_MAX
74 #define STK_C_BLOCKPOOL_MAX (8U)
84#define STK_BLOCKPOOL_ALIGN (sizeof(stk_word_t))
92#define STK_BLOCKPOOL_ALIGN_BLOCK_SIZE(raw_size) \
93 (((raw_size) < STK_BLOCKPOOL_ALIGN) \
94 ? STK_BLOCKPOOL_ALIGN \
95 : (((raw_size) + (STK_BLOCKPOOL_ALIGN - 1U)) & ~(STK_BLOCKPOOL_ALIGN - 1U)))
102#define STK_BLOCKPOOL_STORAGE_SIZE(capacity, raw_block_size) \
103 ((capacity) * STK_BLOCKPOOL_ALIGN_BLOCK_SIZE(raw_block_size))
122#define STK_BLOCKPOOL_STORAGE_DECL(name, capacity, raw_block_size) \
123 static stk_word_t name[STK_BLOCKPOOL_STORAGE_SIZE(capacity, raw_block_size) / sizeof(stk_word_t)]
155 size_t raw_block_size,
176 size_t raw_block_size,
C language binding/interface for SuperTinyKernel RTOS.
int32_t stk_timeout_t
Timeout value.
size_t stk_blockpool_get_capacity(const stk_blockpool_t *pool)
Get the total block capacity of the pool.
void * stk_blockpool_timed_alloc(stk_blockpool_t *pool, stk_timeout_t timeout)
Allocate one block, blocking until one becomes available or the timeout expires.
void stk_blockpool_destroy(stk_blockpool_t *pool)
Destroy a pool and return its slot to the static pool.
bool stk_blockpool_is_storage_valid(const stk_blockpool_t *pool)
Verify that the backing storage is valid and the pool is ready for use.
size_t stk_blockpool_get_used_count(const stk_blockpool_t *pool)
Get the number of currently allocated (outstanding) blocks.
void * stk_blockpool_alloc(stk_blockpool_t *pool)
Allocate one block, blocking indefinitely until one is available.
bool stk_blockpool_free(stk_blockpool_t *pool, void *ptr)
Return a previously allocated block to the pool.
void * stk_blockpool_try_alloc(stk_blockpool_t *pool)
Non-blocking allocation attempt.
stk_blockpool_t * stk_blockpool_create_static(size_t capacity, size_t raw_block_size, uint8_t *storage, size_t storage_size, const char *name)
Create a block pool backed by caller-supplied (external) storage.
stk_blockpool_t * stk_blockpool_create(size_t capacity, size_t raw_block_size, const char *name)
Create a block pool backed by heap-allocated storage.
bool stk_blockpool_is_empty(const stk_blockpool_t *pool)
Check whether all blocks are free (no outstanding allocations).
bool stk_blockpool_is_full(const stk_blockpool_t *pool)
Check whether all blocks are currently allocated (pool exhausted).
size_t stk_blockpool_get_free_count(const stk_blockpool_t *pool)
Get the number of free (available) blocks.
size_t stk_blockpool_get_block_size(const stk_blockpool_t *pool)
Get the aligned block size used internally by the allocator.