LimitedPoolAllocator (for TX queue)

This commit is contained in:
Pavel Kirienko
2014-04-12 13:40:15 +04:00
parent 74b62cc3a9
commit 5808bfc0c9
3 changed files with 80 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#include <uavcan/dynamic_memory.hpp>
namespace uavcan
{
/*
* LimitedPoolAllocator
*/
void* LimitedPoolAllocator::allocate(std::size_t size)
{
if (used_blocks_ < max_blocks_)
{
used_blocks_++;
return allocator_.allocate(size);
}
else
{
return NULL;
}
}
void LimitedPoolAllocator::deallocate(const void* ptr)
{
allocator_.deallocate(ptr);
assert(used_blocks_ > 0);
if (used_blocks_ > 0)
{
used_blocks_--;
}
}
}