Skip to content

Commit 5abbccb

Browse files
mprsePrzemyslaw Stekiel
authored and
Przemyslaw Stekiel
committedAug 21, 2017
Fix pool buffer size, update free() description, add assertion in MemoryPool.h header file.
Provide fix for pool buffer size: pool block size must be a multiple of 4 bytes. Add assertion to forbid creation of MemoryPool object with queue size equal to 0. Update description of free() function. Add information about statuses returned by this function.
1 parent c72d60a commit 5abbccb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎rtos/MemoryPool.h

+7-2
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)
Please sign in to comment.