C API memory pool definitions.
More...
C API memory pool definitions.
- For the complete definition, see
- RTOS C++ API
- Examples
typedef struct my_blk_s
{
int i;
const char* s;
} my_blk_t;
int
{
my_blk_t* blk;
{
}
{
static char pool[1000];
}
}
os_clock_t * os_clock_get_rtclock(void)
Get rtclock (the real-time clock).
os_result_t os_mempool_free(os_mempool_t *mempool, void *block)
Free the memory block.
void os_mempool_construct(os_mempool_t *mempool, const char *name, size_t blocks, size_t block_size_bytes, const os_mempool_attr_t *attr)
Construct a statically allocated memory pool object instance.
void * os_mempool_alloc(os_mempool_t *mempool)
Allocate a memory block.
void * os_mempool_timed_alloc(os_mempool_t *mempool, os_clock_duration_t timeout)
Allocate a memory block with timeout.
void os_mempool_attr_init(os_mempool_attr_t *attr)
Initialise the memory pool attributes.
void * os_mempool_try_alloc(os_mempool_t *mempool)
Try to allocate a memory block.
os_result_t os_mempool_reset(os_mempool_t *mempool)
Reset the memory pool.
void os_mempool_destruct(os_mempool_t *mempool)
Destruct the statically allocated memory pool object instance.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
size_t mp_pool_size_bytes
Size of user provided memory pool area, in bytes.
void * mp_pool_address
Pointer to user provided memory pool area.
void * clock
Pointer to clock object instance.
Memory pool object storage.
◆ os_mempool_create
◆ os_mempool_destroy
◆ os_mempool_attr_t
◆ os_mempool_t
Memory pool object storage.
This C structure has the same size as the C++ os::rtos::memory_pool
object and must be initialised with os_mempool_create()
.
Later on a pointer to it can be used both in C and C++ to refer to the memory pool object instance.
The members of this structure are hidden and should not be used directly, but only through specific functions.
- See also
- os::rtos::memory_pool
◆ os_mempool_alloc()
Allocate a memory block.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- Pointer to memory block, or
NULL
if interrupted.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::alloc()
Definition at line 2389 of file os-c-wrapper.cpp.
◆ os_mempool_attr_init()
Initialise the memory pool attributes.
- Parameters
-
[in] | attr | Pointer to memory pool attributes object instance. |
- Returns
- Nothing.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::attributes
Definition at line 2282 of file os-c-wrapper.cpp.
◆ os_mempool_construct()
Construct a statically allocated memory pool object instance.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance storage. |
[in] | name | Pointer to name (may be NULL). |
[in] | blocks | The maximum number of items in the pool. |
[in] | block_size_bytes | The size of an item, in bytes. |
[in] | attr | Pointer to attributes (may be NULL). |
- Returns
- Nothing.
- Note
- Must be paired with
os_mempool_destruct()
.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool
Definition at line 2297 of file os-c-wrapper.cpp.
◆ os_mempool_delete()
Destruct the memory pool object instance and deallocate it.
- Parameters
-
[in] | mempool | Pointer to dynamically allocated memory pool object instance. |
- Returns
- Nothing.
Destruct the memory pool and deallocate the dynamically allocated space using the RTOS system allocator.
- Note
- Equivalent of C++
delete ptr_mempool
.
-
Must be paired with
os_mempool_new()
.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool
Definition at line 2363 of file os-c-wrapper.cpp.
◆ os_mempool_destruct()
Destruct the statically allocated memory pool object instance.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- Nothing.
- Note
- Must be paired with
os_mempool_construct()
.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool
Definition at line 2318 of file os-c-wrapper.cpp.
◆ os_mempool_free()
Free the memory block.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
[in] | block | Pointer to memory block to free. |
- Return values
-
os_ok | The memory block was released. |
EINVAL | The block does not belong to the memory pool. |
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::free()
Definition at line 2428 of file os-c-wrapper.cpp.
◆ os_mempool_get_block_size()
Get block size.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- The block size, in bytes.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::block_size()
Definition at line 2467 of file os-c-wrapper.cpp.
◆ os_mempool_get_capacity()
Get memory pool capacity.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- The max number of blocks in the pool.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::capacity()
Definition at line 2441 of file os-c-wrapper.cpp.
◆ os_mempool_get_count()
Get blocks count.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- The number of blocks used from the queue.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::count()
Definition at line 2454 of file os-c-wrapper.cpp.
◆ os_mempool_get_name()
Get the memory pool name.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- Null terminated string.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::name()
Definition at line 2376 of file os-c-wrapper.cpp.
◆ os_mempool_get_pool()
Get the pool storage address.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- Pointer to storage.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::pool()
Definition at line 2519 of file os-c-wrapper.cpp.
◆ os_mempool_is_empty()
Check if the memory pool is empty.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Return values
-
true | The memory pool has no allocated blocks. |
false | The memory pool has allocated blocks. |
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::empty()
Definition at line 2480 of file os-c-wrapper.cpp.
◆ os_mempool_is_full()
Check if the memory pool is full.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Return values
-
true | All memory blocks are allocated. |
false | There are still memory blocks that can be allocated. |
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::full()
Definition at line 2493 of file os-c-wrapper.cpp.
◆ os_mempool_new()
Allocate a memory pool object instance and construct it.
- Parameters
-
[in] | name | Pointer to name (may be NULL). |
[in] | blocks | The maximum number of items in the pool. |
[in] | block_size_bytes | The size of an item, in bytes. |
[in] | attr | Pointer to attributes (may be NULL). |
- Returns
- Pointer to new memory pool object instance.
Dynamically allocate the memory pool object instance using the RTOS system allocator and construct it.
- Note
- Equivalent of C++
new memory_pool(...)
.
-
Must be paired with
os_mempool_delete()
.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool
Definition at line 2338 of file os-c-wrapper.cpp.
◆ os_mempool_reset()
Reset the memory pool.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Return values
-
os_ok | The memory pool was reset. |
EPERM | Cannot be invoked from an Interrupt Service Routines. |
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::reset()
Definition at line 2506 of file os-c-wrapper.cpp.
◆ os_mempool_timed_alloc()
Allocate a memory block with timeout.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
[in] | timeout | Timeout to wait, in clock units (ticks or seconds). |
- Returns
- Pointer to memory block, or
NULL
if timeout.
- Warning
- Cannot be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::timed_alloc()
Definition at line 2415 of file os-c-wrapper.cpp.
◆ os_mempool_try_alloc()
Try to allocate a memory block.
- Parameters
-
[in] | mempool | Pointer to memory pool object instance. |
- Returns
- Pointer to memory block, or
NULL
if no memory available.
- Note
- Can be invoked from Interrupt Service Routines.
- For the complete definition, see
- os::rtos::memory_pool::try_alloc()
Definition at line 2402 of file os-c-wrapper.cpp.