UTIL_THROW(CompressedException,"This looks like an xz file, but xz support was not compiled in.");
#endif
default:
UTIL_THROW_IF(require_compressed,CompressedException,"Uncompressed data detected after a compresssed file. This could be supported but usually indicates an error.");
UTIL_THROW_IF(config.total_memory<config.entry_size*config.block_count,ChainConfigException,config.total_memory<<" total memory, too small for "<<config.block_count<<" blocks of containing entries of size "<<config.entry_size);
// Round down block size to a multiple of entry size.
* and runs that worker in a new Thread owned by this chain.
*/
Chain&operator>>(constRecycler&){
CompleteLoop();
return*this;
}
/**
* Adds a WriteAndRecycle worker to this chain,
* and runs that worker in a new Thread owned by this chain.
*/
Chain&operator>>(constWriteAndRecycle&writer);
// Chains are reusable. Call Wait to wait for everything to finish and free memory.
voidWait(boolrelease_memory=true);
// Waits for the current chain to complete (if any) then starts again.
voidStart();
boolRunning()const{return!queues_.empty();}
private:
ChainPositionComplete();
ChainConfigconfig_;
std::size_tblock_size_;
scoped_mallocmemory_;
boost::ptr_vector<PCQueue<Block>>queues_;
boolcomplete_called_;
boost::ptr_vector<Thread>threads_;
MultiProgressprogress_;
};
// Create the link in the worker thread using the position token.
/**
* Represents a C++ style iterator over @ref Block "blocks".
*/
classLink{
public:
// Either default construct and Init or just construct all at once.
/**
* Constructs an @ref Init "initialized" link.
*
* @see Init
*/
explicitLink(constChainPosition&position);
/**
* Constructs a link that must subsequently be @ref Init "initialized".
*
* @see Init
*/
Link();
/**
* Initializes the link with the input @ref PCQueue "consumer queue" and output @ref PCQueue "producer queue" at a given @ref ChainPosition "position" in the @ref Chain "chain".
*
* @see Link()
*/
voidInit(constChainPosition&position);
/**
* Destructs the link object.
*
* If necessary, this method will pass a poison block
* to this link's output @ref PCQueue "producer queue".
*
* @see Block::SetToPoison()
*/
~Link();
/**
* Gets a reference to the @ref Block "block" at this link.
*/
Block&operator*(){returncurrent_;}
/**
* Gets a const reference to the @ref Block "block" at this link.
*/
constBlock&operator*()const{returncurrent_;}
/**
* Gets a pointer to the @ref Block "block" at this link.
*/
Block*operator->(){return¤t_;}
/**
* Gets a const pointer to the @ref Block "block" at this link.
*/
constBlock*operator->()const{return¤t_;}
/**
* Gets the link at the next @ref ChainPosition "position" in the @ref Chain "chain".
*/
Link&operator++();
/**
* Returns true if the @ref Block "block" at this link encapsulates a valid (non-NULL) block of memory.
*
* This method is a user-defined implicit conversion function to boolean;
* among other things, this method enables bare instances of this class
* to be used as the condition of an if statement.
*/
operatorbool()const{returncurrent_;}
/**
* @ref Block::SetToPoison() "Poisons" the @ref Block "block" at this link,
* and passes this now-poisoned block to this link's output @ref PCQueue "producer queue".