@@ -44,6 +44,7 @@ namespace rtos {
44
44
*/
45
45
template <typename T, uint32_t pool_sz>
46
46
class MemoryPool : private mbed ::NonCopyable<MemoryPool<T, pool_sz> > {
47
+ MBED_STATIC_ASSERT (pool_sz > 0 , " Invalid memory pool size. Must be greater than 0." );
47
48
public:
48
49
/* * Create and Initialize a memory pool. */
49
50
MemoryPool () {
@@ -83,7 +84,10 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
83
84
84
85
/* * Free a memory block.
85
86
@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
+
87
91
*/
88
92
osStatus free (T *block) {
89
93
return osMemoryPoolFree (_id, (void *)block);
@@ -92,7 +96,8 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
92
96
private:
93
97
osMemoryPoolId_t _id;
94
98
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];
96
101
mbed_rtos_storage_mem_pool_t _obj_mem;
97
102
};
98
103
0 commit comments