mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-02 03:10:35 +08:00
LimitedPoolAllocator (for TX queue)
This commit is contained in:
@@ -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_--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user