43 using Buff = StreamType::ImplFacade::DataBuffer;
51 return static_cast<Buff*
> (mem);
62 return storage == &inQuestion;
66 inline function<bool(Block const&)>
74 pick_Block_by_storage (VEC& vec,
void* blockLocation)
76 typename VEC::iterator pos
77 = std::find_if (vec.begin(),vec.end()
107 size_t memBlockSize_;
108 PoolHolder blockList_;
118 initialise (
size_t blockSize)
121 memBlockSize_ = blockSize;
128 if (!verify_all_children_idle())
129 ERROR (
test,
"Block actively in use while shutting down BufferProvider " 130 "allocation pool. This might lead to Segfault and memory leaks.");
135 prepare_for (uint number_of_expected_buffers)
137 if (maxAllocCount_ &&
138 maxAllocCount_ < blockList_->size() + number_of_expected_buffers)
140 ASSERT (maxAllocCount_ >= blockList_->size());
141 return maxAllocCount_ - blockList_->size();
144 return number_of_expected_buffers;
151 return blockList_->manage (
new Block(memBlockSize_));
156 find (
void* blockLocation)
158 return pick_Block_by_storage (*blockList_, blockLocation);
163 transferResponsibility (
Block* allocatedBlock)
165 return blockList_->detach (allocatedBlock);
172 return blockList_->size();
178 return bool(blockList_);
182 operator bool()
const 189 verify_all_children_idle()
193 return and_all (*blockList_, is_in_sane_state);
201 is_in_sane_state (
Block const& block)
203 return not block.was_used() or block.was_closed();
212 const uint MAX_BUFFERS = 50;
225 , pool_(new
diagn::PoolTable)
229 TrackingHeapBlockProvider::~TrackingHeapBlockProvider()
231 INFO (proc_mem,
"discarding %zu diagnostic buffer entries", outSeq_.size());
238 TrackingHeapBlockProvider::prepareBuffers(uint requestedAmount,
HashVal typeID)
241 return responsiblePool.prepare_for (requestedAmount);
246 TrackingHeapBlockProvider::provideLockedBuffer(
HashVal typeID)
250 return buildHandle (typeID, asBuffer(newBlock.accessMemory()), &newBlock);
255 TrackingHeapBlockProvider::mark_emitted (
HashVal typeID,
LocalTag const& specifics)
257 diagn::Block* block4buffer = locateBlock (typeID, specifics);
259 throw error::Logic (
"Attempt to emit a buffer not known to this BufferProvider" 260 , LUMIERA_ERROR_BUFFER_MANAGEMENT);
262 outSeq_.manage (pool.transferResponsibility (block4buffer));
270 diagn::Block* block4buffer = locateBlock (typeID, specifics);
271 REQUIRE (block4buffer,
"releasing a buffer not allocated through this provider");
272 REQUIRE (util::isSameAdr (storage, block4buffer->accessMemory()));
273 block4buffer->markReleased();
281 TrackingHeapBlockProvider::emittedCnt()
const 283 return outSeq_.size();
287 TrackingHeapBlockProvider::access_emitted (uint bufferID)
289 if (!withinOutputSequence (bufferID))
290 return emptyPlaceholder;
292 return outSeq_[bufferID];
296 TrackingHeapBlockProvider::withinOutputSequence (uint bufferID)
const 298 if (bufferID >= MAX_BUFFERS)
299 throw error::Fatal (
"hardwired internal limit for test buffers exceeded");
301 return bufferID < outSeq_.size();
305 TrackingHeapBlockProvider::getBlockPoolFor (
HashVal typeID)
309 pool.initialise(getBufferSize(typeID));
314 TrackingHeapBlockProvider::locateBlock (
HashVal typeID,
void* storage)
318 return block4buffer? block4buffer
319 : searchInOutSeqeuence (storage);
323 TrackingHeapBlockProvider::searchInOutSeqeuence (
void* blockLocation)
325 return pick_Block_by_storage (outSeq_, blockLocation);
Helper for implementing a diagnostic BufferProvider: A block of heap allocated storage, with the capability to store some additional tracking information.
Some wrappers for coping with ownership problems.
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error...
virtual void detachBuffer(HashVal, LocalTag const &, Buff &) override
mark a buffer as officially discarded
bool and_all(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
This header is for including and configuring NoBug.
an opaque mark to be used by the BufferProvider implementation.
Steam-Layer implementation namespace root.
Managing lifecycle for a collection of objects.
bool identifyBlock(Block const &inQuestion, void *storage)
helper to find Block entries based on their raw memory address
Simple vector based collection of pointers, managing lifecycle of the pointed-to objects.
Derived specific exceptions within Lumiera's exception hierarchy.
TrackingHeapBlockProvider()
Dummy implementation of the BufferProvider interface to support writing unit tests.
Inline buffer holding and owning an object similar to unique_ptr.
Lumiera error handling (C++ interface).
Handle for a buffer for processing data, abstracting away the actual implementation.
size_t HashVal
a STL compatible hash value
Interface: a facility providing and managing working buffers for media calculations.
BuffHandle buildHandle(HashVal typeID, Buff *storage, LocalTag const &=LocalTag::UNKNOWN)
callback from implementation to build and enrol a BufferHandle, to be returned to the client as resul...
placeholder type for the contents of a data buffer.
Perform operations "for each element" of a collection.
function< bool(Block const &)> search_for_block_using_this_storage(void *storage)
build a searching predicate