Skip to content

Update of MemoryPool.h header file. #4941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rtos/MemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace rtos {
*/
template<typename T, uint32_t pool_sz>
class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
MBED_STATIC_ASSERT(pool_sz > 0, "Invalid memory pool size. Must be greater than 0.");
public:
/** Create and Initialize a memory pool. */
MemoryPool() {
Expand Down Expand Up @@ -83,7 +84,10 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {

/** Free a memory block.
@param block address of the allocated memory block to be freed.
@return status code that indicates the execution status of the function.
@return osOK on successful deallocation, osErrorParameter if given memory block id
is NULL or invalid, or osErrorResource if given memory block is in an
invalid memory pool state.

*/
osStatus free(T *block) {
return osMemoryPoolFree(_id, (void*)block);
Expand All @@ -92,7 +96,8 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
private:
osMemoryPoolId_t _id;
osMemoryPoolAttr_t _attr;
char _pool_mem[sizeof(T) * pool_sz];
/* osMemoryPoolNew requires that pool block size is a multiple of 4 bytes. */
char _pool_mem[((sizeof(T) + 3) & ~3) * pool_sz];
mbed_rtos_storage_mem_pool_t _obj_mem;
};

Expand Down