Skip to content

Commit 3e00a22

Browse files
Merge pull request #4941 from mprse/fix_mem_pool_header_file
Update of MemoryPool.h header file.
2 parents 12d0340 + 5abbccb commit 3e00a22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rtos/MemoryPool.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace rtos {
4444
*/
4545
template<typename T, uint32_t pool_sz>
4646
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.");
4748
public:
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> > {
9296
private:
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

Comments
 (0)