mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 22:03:35 +08:00
Allocator interface: getNumBlocks() --> getBlockCapacity()
This commit is contained in:
@@ -49,7 +49,7 @@ TEST(DynamicMemory, LimitedPoolAllocator)
|
||||
uavcan::PoolAllocator<128, 32> pool32;
|
||||
uavcan::LimitedPoolAllocator lim(pool32, 2);
|
||||
|
||||
EXPECT_EQ(2, lim.getNumBlocks());
|
||||
EXPECT_EQ(2, lim.getBlockCapacity());
|
||||
EXPECT_EQ(0, pool32.getPeakNumUsedBlocks());
|
||||
|
||||
const void* ptr1 = lim.allocate(1);
|
||||
|
||||
@@ -12,13 +12,12 @@ TEST(HeapBasedPoolAllocator, Basic)
|
||||
std::cout << ">>> HEAP BEFORE:" << std::endl;
|
||||
malloc_stats();
|
||||
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize> al(64);
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize> al(0xEEEE);
|
||||
|
||||
ASSERT_EQ(0, al.getNumCachedBlocks());
|
||||
|
||||
ASSERT_EQ(64, al.getNumBlocks());
|
||||
al.setReportedNumBlocks(123);
|
||||
ASSERT_EQ(123, al.getNumBlocks());
|
||||
ASSERT_EQ(0xEEEE, al.getBlockCapacity());
|
||||
ASSERT_EQ(0xFFFF, al.getBlockCapacityHardLimit());
|
||||
|
||||
void* a = al.allocate(10);
|
||||
void* b = al.allocate(10);
|
||||
@@ -74,7 +73,10 @@ TEST(HeapBasedPoolAllocator, Concurrency)
|
||||
std::cout << ">>> HEAP BEFORE:" << std::endl;
|
||||
malloc_stats();
|
||||
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, RaiiSynchronizer> al(1);
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, RaiiSynchronizer> al(1000);
|
||||
|
||||
ASSERT_EQ(1000, al.getBlockCapacity());
|
||||
ASSERT_EQ(2000, al.getBlockCapacityHardLimit());
|
||||
|
||||
volatile bool terminate = false;
|
||||
|
||||
|
||||
@@ -316,5 +316,5 @@ class NullAllocator : public uavcan::IPoolAllocator
|
||||
public:
|
||||
virtual void* allocate(std::size_t) { return NULL; }
|
||||
virtual void deallocate(const void*) { }
|
||||
virtual uint16_t getNumBlocks() const { return 0; }
|
||||
virtual uint16_t getBlockCapacity() const { return 0; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user