Dynamic memory refactoring: Entire library now uses IPoolAllocator instead of IAllocator, which was removed completely. This change was needed to enable TX queue constraints, see the next commits.

This commit is contained in:
Pavel Kirienko
2014-04-12 17:17:06 +04:00
parent 5808bfc0c9
commit 4e7287358a
14 changed files with 120 additions and 61 deletions
@@ -59,7 +59,7 @@ public:
IsDynamicallyAllocatable<Entry>::check();
}
static void destroy(Entry*& obj, IAllocator& allocator);
static void destroy(Entry*& obj, IPoolAllocator& allocator);
bool isExpired(MonotonicTime timestamp) const { return timestamp > deadline; }
@@ -87,7 +87,7 @@ private:
};
LinkedListRoot<Entry> queue_;
IAllocator* const allocator_;
IPoolAllocator* const allocator_;
ISystemClock* const sysclock_;
uint32_t rejected_frames_cnt_;
@@ -100,7 +100,7 @@ public:
, rejected_frames_cnt_(0)
{ }
CanTxQueue(IAllocator* allocator, ISystemClock* sysclock)
CanTxQueue(IPoolAllocator* allocator, ISystemClock* sysclock)
: allocator_(allocator)
, sysclock_(sysclock)
, rejected_frames_cnt_(0)
@@ -160,7 +160,7 @@ class UAVCAN_EXPORT CanIOManager : Noncopyable
int callSelect(CanSelectMasks& inout_masks, MonotonicTime blocking_deadline);
public:
CanIOManager(ICanDriver& driver, IAllocator& allocator, ISystemClock& sysclock)
CanIOManager(ICanDriver& driver, IPoolAllocator& allocator, ISystemClock& sysclock)
: driver_(driver)
, sysclock_(sysclock)
{
@@ -102,7 +102,7 @@ class UAVCAN_EXPORT Dispatcher : Noncopyable
void handleLoopbackFrame(const CanRxFrame& can_frame);
public:
Dispatcher(ICanDriver& driver, IAllocator& allocator, ISystemClock& sysclock, IOutgoingTransferRegistry& otr)
Dispatcher(ICanDriver& driver, IPoolAllocator& allocator, ISystemClock& sysclock, IOutgoingTransferRegistry& otr)
: canio_(driver, allocator, sysclock)
, sysclock_(sysclock)
, outgoing_transfer_reg_(otr)
@@ -122,7 +122,7 @@ class UAVCAN_EXPORT OutgoingTransferRegistry : public IOutgoingTransferRegistry,
Map<OutgoingTransferRegistryKey, Value, NumStaticEntries> map_;
public:
OutgoingTransferRegistry(IAllocator& allocator)
OutgoingTransferRegistry(IPoolAllocator& allocator)
: map_(allocator)
{ }
@@ -107,8 +107,8 @@ class UAVCAN_EXPORT DynamicTransferBufferManagerEntry
enum { Size = MemPoolBlockSize - sizeof(LinkedListNode<Block>) };
uint8_t data[Size];
static Block* instantiate(IAllocator& allocator);
static void destroy(Block*& obj, IAllocator& allocator);
static Block* instantiate(IPoolAllocator& allocator);
static void destroy(Block*& obj, IPoolAllocator& allocator);
void read(uint8_t*& outptr, unsigned target_offset,
unsigned& total_offset, unsigned& left_to_read);
@@ -116,7 +116,7 @@ class UAVCAN_EXPORT DynamicTransferBufferManagerEntry
unsigned& total_offset, unsigned& left_to_write);
};
IAllocator& allocator_;
IPoolAllocator& allocator_;
LinkedListRoot<Block> blocks_; // Blocks are ordered from lower to higher buffer offset
uint16_t max_write_pos_;
const uint16_t max_size_;
@@ -124,7 +124,7 @@ class UAVCAN_EXPORT DynamicTransferBufferManagerEntry
void resetImpl();
public:
DynamicTransferBufferManagerEntry(IAllocator& allocator, uint16_t max_size)
DynamicTransferBufferManagerEntry(IPoolAllocator& allocator, uint16_t max_size)
: allocator_(allocator)
, max_write_pos_(0)
, max_size_(max_size)
@@ -139,8 +139,8 @@ public:
resetImpl();
}
static DynamicTransferBufferManagerEntry* instantiate(IAllocator& allocator, uint16_t max_size);
static void destroy(DynamicTransferBufferManagerEntry*& obj, IAllocator& allocator);
static DynamicTransferBufferManagerEntry* instantiate(IPoolAllocator& allocator, uint16_t max_size);
static void destroy(DynamicTransferBufferManagerEntry*& obj, IPoolAllocator& allocator);
int read(unsigned offset, uint8_t* data, unsigned len) const;
int write(unsigned offset, const uint8_t* data, unsigned len);
@@ -258,7 +258,7 @@ public:
class TransferBufferManagerImpl : public ITransferBufferManager, Noncopyable
{
LinkedListRoot<DynamicTransferBufferManagerEntry> dynamic_buffers_;
IAllocator& allocator_;
IPoolAllocator& allocator_;
const uint16_t max_buf_size_;
virtual StaticTransferBufferManagerEntryImpl* getStaticByIndex(uint16_t index) const = 0;
@@ -268,7 +268,7 @@ class TransferBufferManagerImpl : public ITransferBufferManager, Noncopyable
void optimizeStorage();
public:
TransferBufferManagerImpl(uint16_t max_buf_size, IAllocator& allocator)
TransferBufferManagerImpl(uint16_t max_buf_size, IPoolAllocator& allocator)
: allocator_(allocator)
, max_buf_size_(max_buf_size)
{ }
@@ -295,7 +295,7 @@ class UAVCAN_EXPORT TransferBufferManager : public TransferBufferManagerImpl
}
public:
TransferBufferManager(IAllocator& allocator)
TransferBufferManager(IPoolAllocator& allocator)
: TransferBufferManagerImpl(MaxBufSize, allocator)
{
StaticAssert<(MaxBufSize > 0)>::check();
@@ -307,7 +307,7 @@ class UAVCAN_EXPORT TransferBufferManager<0, 0> : public ITransferBufferManager
{
public:
TransferBufferManager() { }
TransferBufferManager(IAllocator&) { }
TransferBufferManager(IPoolAllocator&) { }
ITransferBuffer* access(const TransferBufferManagerKey&) { return NULL; }
ITransferBuffer* create(const TransferBufferManagerKey&) { return NULL; }
void remove(const TransferBufferManagerKey&) { }
@@ -145,7 +145,7 @@ class UAVCAN_EXPORT TransferListener : public TransferListenerBase
Map<TransferBufferManagerKey, TransferReceiver, NumStaticReceivers> receivers_;
public:
TransferListener(TransferPerfCounter& perf, const DataTypeDescriptor& data_type, IAllocator& allocator)
TransferListener(TransferPerfCounter& perf, const DataTypeDescriptor& data_type, IPoolAllocator& allocator)
: TransferListenerBase(perf, data_type, receivers_, bufmgr_)
, bufmgr_(allocator)
, receivers_(allocator)
@@ -200,7 +200,7 @@ private:
public:
ServiceResponseTransferListener(TransferPerfCounter& perf, const DataTypeDescriptor& data_type,
IAllocator& allocator)
IPoolAllocator& allocator)
: BaseType(perf, data_type, allocator)
{ }