C API memory pool definitions.
More...
- 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
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()
- 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 2576 of file os-c-wrapper.cpp.
2577{
2578 assert (mempool != nullptr);
2579 return (
reinterpret_cast<memory_pool&
> (*mempool)).alloc ();
2580}
Synchronised memory pool, using the default RTOS allocator.
◆ os_mempool_attr_init()
- 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 2469 of file os-c-wrapper.cpp.
2470{
2471 assert (attr != nullptr);
2473}
◆ os_mempool_construct()
- 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 2484 of file os-c-wrapper.cpp.
2486{
2487 assert (mempool != nullptr);
2488 if (attr == nullptr)
2489 {
2491 }
2492 new (mempool)
memory_pool (name, blocks, block_size_bytes,
2494}
static const attributes initializer
Default memory pool initialiser.
References os::rtos::memory_pool::initializer.
◆ os_mempool_delete()
- 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 2550 of file os-c-wrapper.cpp.
2551{
2552 assert (mempool != nullptr);
2554}
◆ os_mempool_destruct()
- 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 2505 of file os-c-wrapper.cpp.
2506{
2507 assert (mempool != nullptr);
2509}
◆ os_mempool_free()
- 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 2615 of file os-c-wrapper.cpp.
2616{
2617 assert (mempool != nullptr);
2619}
uint32_t os_result_t
Type of values returned by RTOS functions.
void free(void *ptr)
Free the allocated memory block.
References free().
◆ os_mempool_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 2654 of file os-c-wrapper.cpp.
2655{
2656 assert (mempool != nullptr);
2657 return (
reinterpret_cast<memory_pool&
> (*mempool)).block_size ();
2658}
◆ os_mempool_get_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 2628 of file os-c-wrapper.cpp.
2629{
2630 assert (mempool != nullptr);
2631 return (
reinterpret_cast<memory_pool&
> (*mempool)).capacity ();
2632}
◆ os_mempool_get_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 2641 of file os-c-wrapper.cpp.
2642{
2643 assert (mempool != nullptr);
2644 return (
reinterpret_cast<memory_pool&
> (*mempool)).count ();
2645}
◆ os_mempool_get_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 2563 of file os-c-wrapper.cpp.
2564{
2565 assert (mempool != nullptr);
2566 return (
reinterpret_cast<memory_pool&
> (*mempool)).name ();
2567}
◆ os_mempool_get_pool()
- 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 2706 of file os-c-wrapper.cpp.
2707{
2708 assert (mempool != nullptr);
2709 return (
void*)(
reinterpret_cast<memory_pool&
> (*mempool)).pool ();
2710}
◆ os_mempool_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 2667 of file os-c-wrapper.cpp.
2668{
2669 assert (mempool != nullptr);
2670 return (
reinterpret_cast<memory_pool&
> (*mempool)).empty ();
2671}
◆ os_mempool_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 2680 of file os-c-wrapper.cpp.
2681{
2682 assert (mempool != nullptr);
2683 return (
reinterpret_cast<memory_pool&
> (*mempool)).full ();
2684}
◆ os_mempool_new()
- 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 2525 of file os-c-wrapper.cpp.
2527{
2528 if (attr == nullptr)
2529 {
2531 }
2534}
References os::rtos::memory_pool::initializer.
◆ os_mempool_reset()
- 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 2693 of file os-c-wrapper.cpp.
2694{
2695 assert (mempool != nullptr);
2697}
◆ os_mempool_timed_alloc()
- 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 2602 of file os-c-wrapper.cpp.
2603{
2604 assert (mempool != nullptr);
2605 return (
reinterpret_cast<memory_pool&
> (*mempool)).timed_alloc (timeout);
2606}
◆ os_mempool_try_alloc()
- 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 2589 of file os-c-wrapper.cpp.
2590{
2591 assert (mempool != nullptr);
2592 return (
reinterpret_cast<memory_pool&
> (*mempool)).try_alloc ();
2593}