SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_c_memory.cpp File Reference
#include <cstddef>
#include <stk_config.h>
#include <stk.h>
#include <memory/stk_memory.h>
#include "stk_c.h"
#include "stk_c_memory.h"
Include dependency graph for stk_c_memory.cpp:

Go to the source code of this file.

Classes

struct  stk_blockpool_t
struct  BlockPoolSlot

Functions

template<typename T>
static constexpr size_t StkGetWordCountForType ()
void * malloc (size_t size)
void free (void *ptr)
static BlockPoolSlotFindSlot (const stk_blockpool_t *pool)
static BlockPoolSlotAcquireSlot ()
stk_blockpool_tstk_blockpool_create (size_t capacity, size_t raw_block_size, const char *name)
 Create a block pool backed by heap-allocated storage.
stk_blockpool_tstk_blockpool_create_static (size_t capacity, size_t raw_block_size, uint8_t *storage_ptr, size_t storage_size, const char *name)
 Create a block pool backed by caller-supplied (external) storage.
void stk_blockpool_destroy (stk_blockpool_t *pool)
 Destroy a pool and return its slot to the static pool.
void * stk_blockpool_alloc (stk_blockpool_t *pool)
 Allocate one block, blocking indefinitely until one is available.
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_try_alloc (stk_blockpool_t *pool)
 Non-blocking allocation attempt.
bool stk_blockpool_free (stk_blockpool_t *pool, void *ptr)
 Return a previously allocated block to the 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_capacity (const stk_blockpool_t *pool)
 Get the total block capacity of the pool.
size_t stk_blockpool_get_block_size (const stk_blockpool_t *pool)
 Get the aligned block size used internally by the allocator.
size_t stk_blockpool_get_used_count (const stk_blockpool_t *pool)
 Get the number of currently allocated (outstanding) blocks.
size_t stk_blockpool_get_free_count (const stk_blockpool_t *pool)
 Get the number of free (available) blocks.
bool stk_blockpool_is_full (const stk_blockpool_t *pool)
 Check whether all blocks are currently allocated (pool exhausted).
bool stk_blockpool_is_empty (const stk_blockpool_t *pool)
 Check whether all blocks are free (no outstanding allocations).

Variables

static struct BlockPoolSlot s_BlockPools [(8U)]

Function Documentation

◆ AcquireSlot()

BlockPoolSlot * AcquireSlot ( )
static

Definition at line 111 of file stk_c_memory.cpp.

112{
113 BlockPoolSlot *result = nullptr;
114
115 for (size_t i = 0U; i < STK_C_BLOCKPOOL_MAX; ++i)
116 {
117 if (!s_BlockPools[i].busy)
118 {
119 s_BlockPools[i].busy = true;
120 result = &s_BlockPools[i];
121 break;
122 }
123 }
124
125 return result;
126}
static struct BlockPoolSlot s_BlockPools[(8U)]
#define STK_C_BLOCKPOOL_MAX
Maximum number of concurrent stk_blockpool_t instances (default: 8).

References s_BlockPools, and STK_C_BLOCKPOOL_MAX.

Referenced by stk_blockpool_create(), and stk_blockpool_create_static().

Here is the caller graph for this function:

◆ FindSlot()

BlockPoolSlot * FindSlot ( const stk_blockpool_t * pool)
static

Definition at line 91 of file stk_c_memory.cpp.

92{
93 BlockPoolSlot *result = nullptr;
94
95 for (size_t i = 0U; i < STK_C_BLOCKPOOL_MAX; ++i)
96 {
97 if (s_BlockPools[i].busy)
98 {
99 if (s_BlockPools[i].pool() == pool)
100 {
101 result = &s_BlockPools[i];
102 break;
103 }
104 }
105 }
106
107 return result;
108}

References s_BlockPools, and STK_C_BLOCKPOOL_MAX.

Referenced by stk_blockpool_destroy().

Here is the caller graph for this function:

◆ free()

void free ( void * ptr)

Referenced by stk::memory::MemoryAllocator::Free().

Here is the caller graph for this function:

◆ malloc()

void * malloc ( size_t size)

Referenced by stk::memory::MemoryAllocator::Allocate().

Here is the caller graph for this function:

◆ StkGetWordCountForType()

template<typename T>
constexpr size_t StkGetWordCountForType ( )
staticconstexpr

Definition at line 35 of file stk_c_memory.cpp.

36{
37 return ((sizeof(T) + sizeof(stk::Word) - 1U) / sizeof(stk::Word));
38}
uintptr_t Word
Native processor word type.
Definition stk_common.h:136

Variable Documentation

◆ s_BlockPools

struct BlockPoolSlot s_BlockPools[ (8U) ]
static

Referenced by AcquireSlot(), and FindSlot().