STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::prefetch_pool< BlockType > Class Template Reference

Detailed Description

template<class BlockType>
class stxxl::prefetch_pool< BlockType >

Implements dynamically resizable prefetching pool.

Definition at line 29 of file prefetch_pool.h.

+ Inheritance diagram for stxxl::prefetch_pool< BlockType >:
+ Collaboration diagram for stxxl::prefetch_pool< BlockType >:

Classes

struct  bid_hash
 

Public Types

typedef block_type::bid_type bid_type
 
typedef BlockType block_type
 

Public Member Functions

 prefetch_pool (unsigned_type init_size=1)
 Constructs pool. More...
 
virtual ~prefetch_pool ()
 Waits for completion of all ongoing read requests and frees memory. More...
 
void add (block_type *&block)
 Add a new block to prefetch pool, enlarges size of pool. More...
 
unsigned_type busy_size () const
 Returns the number of busy prefetching blocks. More...
 
request_ptr find (bid_type bid)
 Returns the request pointer for a hinted block, or an invalid NULL request in case it was not requested due to lack of prefetch buffers. More...
 
unsigned_type free_size () const
 Returns the number of free prefetching blocks. More...
 
bool hint (bid_type bid)
 Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer. More...
 
bool hint (bid_type bid, write_pool< block_type > &w_pool)
 Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer. More...
 
bool in_prefetching (bid_type bid)
 Checks if a block is in the hinted block set. More...
 
bool invalidate (bid_type bid)
 Cancel a hint request in case the block is no longer desired. More...
 
bool poll (bid_type bid)
 Returns true if the blocks was hinted and the request is finished. More...
 
request_ptr read (block_type *&block, bid_type bid)
 Reads block. More...
 
request_ptr read (block_type *&block, bid_type bid, write_pool< block_type > &w_pool)
 
unsigned_type resize (unsigned_type new_size)
 Resizes size of the pool. More...
 
unsigned_type size () const
 Returns number of owned blocks. More...
 
block_typesteal ()
 Take out a block from the pool, one unhinted free block must be available. More...
 
void swap (prefetch_pool &obj)
 

Protected Types

typedef hash_map_type::iterator busy_blocks_iterator
 
typedef std::pair< block_type
*, request_ptr
busy_entry
 
typedef std::list< block_type * >
::iterator 
free_blocks_iterator
 
typedef compat_hash_map
< bid_type, busy_entry,
bid_hash >::result 
hash_map_type
 

Protected Attributes

hash_map_type busy_blocks
 blocks that are in reading or already read but not retrieved by user More...
 
std::list< block_type * > free_blocks
 contains free prefetch blocks More...
 
unsigned_type free_blocks_size
 count number of free blocks, since traversing the std::list is slow. More...
 

Additional Inherited Members

- Private Member Functions inherited from stxxl::noncopyable
 noncopyable ()
 

Member Typedef Documentation

template<class BlockType>
typedef block_type::bid_type stxxl::prefetch_pool< BlockType >::bid_type

Definition at line 33 of file prefetch_pool.h.

template<class BlockType>
typedef BlockType stxxl::prefetch_pool< BlockType >::block_type

Definition at line 32 of file prefetch_pool.h.

template<class BlockType>
typedef hash_map_type::iterator stxxl::prefetch_pool< BlockType >::busy_blocks_iterator
protected

Definition at line 60 of file prefetch_pool.h.

template<class BlockType>
typedef std::pair<block_type*, request_ptr> stxxl::prefetch_pool< BlockType >::busy_entry
protected

Definition at line 57 of file prefetch_pool.h.

template<class BlockType>
typedef std::list<block_type*>::iterator stxxl::prefetch_pool< BlockType >::free_blocks_iterator
protected

Definition at line 59 of file prefetch_pool.h.

template<class BlockType>
typedef compat_hash_map<bid_type, busy_entry, bid_hash>::result stxxl::prefetch_pool< BlockType >::hash_map_type
protected

Definition at line 58 of file prefetch_pool.h.

Constructor & Destructor Documentation

template<class BlockType>
stxxl::prefetch_pool< BlockType >::prefetch_pool ( unsigned_type  init_size = 1)
inlineexplicit

Constructs pool.

Parameters
init_sizeinitial number of blocks in the pool

Definition at line 74 of file prefetch_pool.h.

template<class BlockType>
virtual stxxl::prefetch_pool< BlockType >::~prefetch_pool ( )
inlinevirtual

Waits for completion of all ongoing read requests and frees memory.

Definition at line 90 of file prefetch_pool.h.

Member Function Documentation

template<class BlockType>
void stxxl::prefetch_pool< BlockType >::add ( block_type *&  block)
inline

Add a new block to prefetch pool, enlarges size of pool.

Definition at line 130 of file prefetch_pool.h.

template<class BlockType>
unsigned_type stxxl::prefetch_pool< BlockType >::busy_size ( ) const
inline

Returns the number of busy prefetching blocks.

Definition at line 124 of file prefetch_pool.h.

template<class BlockType>
request_ptr stxxl::prefetch_pool< BlockType >::find ( bid_type  bid)
inline

Returns the request pointer for a hinted block, or an invalid NULL request in case it was not requested due to lack of prefetch buffers.

Definition at line 255 of file prefetch_pool.h.

template<class BlockType>
unsigned_type stxxl::prefetch_pool< BlockType >::free_size ( ) const
inline

Returns the number of free prefetching blocks.

Definition at line 118 of file prefetch_pool.h.

template<class BlockType>
bool stxxl::prefetch_pool< BlockType >::hint ( bid_type  bid)
inline

Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer.

Parameters
bidaddress of a block to be prefetched
Returns
true if there was a free block to do prefetch and prefetching was scheduled, false otherwise
Note
If there are no free blocks available (all blocks are already in reading or read but not retrieved by user calling read method) calling hint function has no effect

Definition at line 162 of file prefetch_pool.h.

References STXXL_VERBOSE2.

template<class BlockType>
bool stxxl::prefetch_pool< BlockType >::hint ( bid_type  bid,
write_pool< block_type > &  w_pool 
)
inline

Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer.

This variant checks if the write pool is currently writing said block.

Parameters
bidaddress of a block to be prefetched
Returns
true if there was a free block to do prefetch and prefetching was scheduled, false otherwise
Note
If there are no free blocks available (all blocks are already in reading or read but not retrieved by user calling read method) calling hint function has no effect

Definition at line 197 of file prefetch_pool.h.

References stxxl::write_pool< BlockType >::add(), stxxl::write_pool< BlockType >::has_request(), stxxl::write_pool< BlockType >::steal_request(), STXXL_VERBOSE1, and STXXL_VERBOSE2.

template<class BlockType>
bool stxxl::prefetch_pool< BlockType >::in_prefetching ( bid_type  bid)
inline

Checks if a block is in the hinted block set.

Definition at line 248 of file prefetch_pool.h.

template<class BlockType>
bool stxxl::prefetch_pool< BlockType >::invalidate ( bid_type  bid)
inline

Cancel a hint request in case the block is no longer desired.

Definition at line 229 of file prefetch_pool.h.

template<class BlockType>
bool stxxl::prefetch_pool< BlockType >::poll ( bid_type  bid)
inline

Returns true if the blocks was hinted and the request is finished.

Definition at line 266 of file prefetch_pool.h.

References stxxl::find(), stxxl::request_interface::poll(), and stxxl::counting_ptr< Type >::valid().

template<class BlockType>
request_ptr stxxl::prefetch_pool< BlockType >::read ( block_type *&  block,
bid_type  bid 
)
inline

Reads block.

If this block is cached block is not read but passed from the cache.

Parameters
blockblock object, where data to be read to. If block was cached block 's ownership goes to the pool and block from cache is returned in block value.
bidaddress of the block
Warning
block parameter must be allocated dynamically using new .
Returns
request pointer object of read operation

Definition at line 286 of file prefetch_pool.h.

References STXXL_VERBOSE1.

template<class BlockType>
unsigned_type stxxl::prefetch_pool< BlockType >::resize ( unsigned_type  new_size)
inline

Resizes size of the pool.

Parameters
new_sizedesired size of the pool. If some blocks are used for prefetching, these blocks can't be freed. Only free blocks (not in prefetching) can be freed by reducing the size of the pool calling this method.
Returns
new size of the pool

Definition at line 344 of file prefetch_pool.h.

template<class BlockType>
unsigned_type stxxl::prefetch_pool< BlockType >::size ( ) const
inline

Returns number of owned blocks.

Definition at line 112 of file prefetch_pool.h.

template<class BlockType>
block_type* stxxl::prefetch_pool< BlockType >::steal ( )
inline

Take out a block from the pool, one unhinted free block must be available.

Returns
pointer to the block. Ownership of the block goes to the caller.

Definition at line 140 of file prefetch_pool.h.

References STXXL_CHECK.

template<class BlockType>
void stxxl::prefetch_pool< BlockType >::swap ( prefetch_pool< BlockType > &  obj)
inline

Member Data Documentation

template<class BlockType>
hash_map_type stxxl::prefetch_pool< BlockType >::busy_blocks
protected

blocks that are in reading or already read but not retrieved by user

Definition at line 66 of file prefetch_pool.h.

Referenced by stxxl::prefetch_pool< BlockType >::swap().

template<class BlockType>
std::list<block_type*> stxxl::prefetch_pool< BlockType >::free_blocks
protected

contains free prefetch blocks

Definition at line 63 of file prefetch_pool.h.

Referenced by stxxl::prefetch_pool< BlockType >::swap().

template<class BlockType>
unsigned_type stxxl::prefetch_pool< BlockType >::free_blocks_size
protected

count number of free blocks, since traversing the std::list is slow.

Definition at line 69 of file prefetch_pool.h.

Referenced by stxxl::prefetch_pool< BlockType >::swap().


The documentation for this class was generated from the following file: