28 #include "rtos/mbed_rtos_types.h" 29 #include "rtos/mbed_rtos1_types.h" 30 #include "rtos/mbed_rtos_storage.h" 31 #include "platform/NonCopyable.h" 32 #include "platform/mbed_assert.h" 36 #if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) 54 template<
typename T, u
int32_t pool_sz>
56 MBED_STATIC_ASSERT(pool_sz > 0,
"Invalid memory pool size. Must be greater than 0.");
64 memset(_pool_mem, 0,
sizeof(_pool_mem));
67 attr.
mp_size =
sizeof(_pool_mem);
69 attr.
cb_size =
sizeof(_obj_mem);
70 _id = osMemoryPoolNew(pool_sz,
sizeof(T), &attr);
80 osMemoryPoolDelete(_id);
90 return (T *)osMemoryPoolAlloc(_id, 0);
101 return (T *)osMemoryPoolAlloc(_id, millisec);
118 if (now >= millisec) {
120 }
else if (millisec - now >= osWaitForever) {
121 delay = osWaitForever - 1;
123 delay = millisec - now;
136 if (item !=
nullptr) {
137 memset(item, 0,
sizeof(T));
151 if (item !=
nullptr) {
152 memset(item, 0,
sizeof(T));
170 if (item !=
nullptr) {
171 memset(item, 0,
sizeof(T));
186 return osMemoryPoolFree(_id, block);
190 osMemoryPoolId_t _id;
191 char _pool_mem[MBED_RTOS_STORAGE_MEM_POOL_MEM_SIZE(pool_sz,
sizeof(T))];
~MemoryPool()
Destroy a memory pool.
Memory Pool Control Block.
Define and manage fixed-size memory pools of objects of a given type.
T * calloc_until(uint64_t millisec)
Allocate a memory block from a memory pool, blocking, and set memory block to zero.
Attributes structure for memory pool.
T * alloc_until(uint64_t millisec)
Allocate a memory block from a memory pool, blocking.
T * alloc_for(uint32_t millisec)
Allocate a memory block from a memory pool, optionally blocking.
void * cb_mem
memory for control block
Prevents generation of copy constructor and copy assignment operator in derived classes.
void * mp_mem
memory for data storage
uint32_t cb_size
size of provided memory for control block
osStatus free(T *block)
Free a memory block.
T * calloc(void)
Allocate a memory block from a memory pool, without blocking, and set memory block to zero...
uint64_t get_ms_count()
Read the current RTOS kernel millisecond tick count.
MemoryPool()
Create and Initialize a memory pool.
T * calloc_for(uint32_t millisec)
Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero...
T * alloc(void)
Allocate a memory block from a memory pool, without blocking.
uint32_t mp_size
size of provided memory for data storage