@@ -44,6 +44,7 @@ namespace rtos {
4444*/
4545template <typename T, uint32_t pool_sz>
4646class MemoryPool : private mbed ::NonCopyable<MemoryPool<T, pool_sz> > {
47+ MBED_STATIC_ASSERT (pool_sz > 0 , " Invalid memory pool size. Must be greater than 0." );
4748public:
4849 /* * Create and Initialize a memory pool. */
4950 MemoryPool () {
@@ -83,7 +84,10 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
8384
8485 /* * Free a memory block.
8586 @param block address of the allocated memory block to be freed.
86- @return status code that indicates the execution status of the function.
87+ @return osOK on successful deallocation, osErrorParameter if given memory block id
88+ is NULL or invalid, or osErrorResource if given memory block is in an
89+ invalid memory pool state.
90+
8791 */
8892 osStatus free (T *block) {
8993 return osMemoryPoolFree (_id, (void *)block);
@@ -92,7 +96,8 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
9296private:
9397 osMemoryPoolId_t _id;
9498 osMemoryPoolAttr_t _attr;
95- char _pool_mem[sizeof (T) * pool_sz];
99+ /* osMemoryPoolNew requires that pool block size is a multiple of 4 bytes. */
100+ char _pool_mem[((sizeof (T) + 3 ) & ~3 ) * pool_sz];
96101 mbed_rtos_storage_mem_pool_t _obj_mem;
97102};
98103
0 commit comments