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, newBlock.accessMemory(), &newBlock);
255 TrackingHeapBlockProvider::mark_emitted (
HashVal typeID,
LocalKey const& implID)
257 diagn::Block* block4buffer = locateBlock (typeID, implID);
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, implID);
271 REQUIRE (block4buffer,
"releasing a buffer not allocated through this provider");
272 block4buffer->markReleased();
280 TrackingHeapBlockProvider::emittedCnt()
const 282 return outSeq_.size();
286 TrackingHeapBlockProvider::access_emitted (uint bufferID)
288 if (!withinOutputSequence (bufferID))
289 return emptyPlaceholder;
291 return outSeq_[bufferID];
295 TrackingHeapBlockProvider::withinOutputSequence (uint bufferID)
const 297 if (bufferID >= MAX_BUFFERS)
298 throw error::Fatal (
"hardwired internal limit for test buffers exceeded");
300 return bufferID < outSeq_.size();
304 TrackingHeapBlockProvider::getBlockPoolFor (
HashVal typeID)
308 pool.initialise(getBufferSize(typeID));
313 TrackingHeapBlockProvider::locateBlock (
HashVal typeID,
void* storage)
317 return block4buffer? block4buffer
318 : searchInOutSeqeuence (storage);
322 TrackingHeapBlockProvider::searchInOutSeqeuence (
void* blockLocation)
324 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...
BuffHandle buildHandle(HashVal typeID, void *storage, LocalKey const &)
callback from implementation to build and enrol a BufferHandle, to be returned to the client as resul...
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.
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()
an opaque ID to be used by the BufferProvider implementation.
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.
Perform operations "for each element" of a collection.
virtual void detachBuffer(HashVal entryID, LocalKey const &)
mark a buffer as officially discarded
function< bool(Block const &)> search_for_block_using_this_storage(void *storage)
build a searching predicate