14 #ifndef STXXL_MNG_PREFETCH_POOL_HEADER
15 #define STXXL_MNG_PREFETCH_POOL_HEADER
28 template <
class BlockType>
33 typedef typename block_type::bid_type
bid_type;
40 size_t result = size_t(bid.storage) +
41 size_t(bid.offset & 0xffffffff) + size_t(bid.offset >> 32);
47 return (a.storage < b.storage) || (a.storage == b.storage && a.offset < b.offset);
74 for ( ; i < init_size; ++i)
88 while (!free_blocks.empty())
90 delete free_blocks.back();
91 free_blocks.pop_back();
97 for ( ; i2 != busy_blocks.end(); ++i2)
99 i2->second.second->wait();
100 delete i2->second.first;
109 {
return free_blocks_size + busy_blocks.size(); }
121 if (in_prefetching(bid)) {
122 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" was already cached");
126 if (free_blocks_size)
130 free_blocks.pop_back();
131 STXXL_VERBOSE2(
"prefetch_pool::hint bid=" << bid <<
" => prefetching");
136 STXXL_VERBOSE2(
"prefetch_pool::hint bid=" << bid <<
" => no free blocks for prefetching");
143 if (in_prefetching(bid)) {
144 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" was already cached");
148 if (free_blocks_size)
152 free_blocks.pop_back();
156 STXXL_VERBOSE1(
"prefetch_pool::hint2 bid=" << bid <<
" was in write cache at " << wp_request.first);
157 assert(wp_request.first != 0);
159 busy_blocks[bid] = wp_request;
162 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" => prefetching");
167 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" => no free blocks for prefetching");
174 if (cache_el == busy_blocks.end())
179 if (cache_el->second.second->get_type() == request::READ)
180 cache_el->second.second->cancel();
182 cache_el->second.second->wait();
184 free_blocks.push_back(cache_el->second.first);
185 busy_blocks.erase(cache_el);
191 return (busy_blocks.find(bid) != busy_blocks.end());
203 if (cache_el == busy_blocks.end())
206 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => no copy in cache, retrieving to " << block);
207 return block->read(bid);
211 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => copy in cache exists");
213 free_blocks.push_back(block);
214 block = cache_el->second.first;
216 busy_blocks.erase(cache_el);
224 if (cache_el != busy_blocks.end())
227 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => copy in cache exists");
229 free_blocks.push_back(block);
230 block = cache_el->second.first;
232 busy_blocks.erase(cache_el);
240 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" was in write cache at " << wp_request.first);
241 assert(wp_request.first != 0);
243 block = wp_request.first;
244 return wp_request.second;
248 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => no copy in cache, retrieving to " << block);
249 return block->read(bid);
263 free_blocks_size += diff;
270 while (diff < 0 && free_blocks_size > 0)
274 delete free_blocks.back();
275 free_blocks.pop_back();
287 template <
class BlockType>
296 #endif // !STXXL_MNG_PREFETCH_POOL_HEADER
bool has_request(bid_type bid)
hash_map_type busy_blocks
bool hint(bid_type bid, write_pool< block_type > &w_pool)
request_ptr read(block_type *&block, bid_type bid, write_pool< block_type > &w_pool)
void swap(prefetch_pool &obj)
bool in_prefetching(bid_type bid)
void add(block_type *&block)
std::list< block_type * > free_blocks
block_type::bid_type bid_type
bool invalidate(bid_type bid)
virtual ~prefetch_pool()
Waits for completion of all ongoing read requests and frees memory.
hash_map_type::iterator busy_blocks_iterator
bool hint(bid_type bid)
Gives a hint for prefetching a block.
#define STXXL_VERBOSE2(x)
std::pair< block_type *, request_ptr > steal_request(bid_type bid)
Implements dynamically resizable buffered writing pool.
unsigned_type free_blocks_size
Implements dynamically resizable prefetching pool.
choose_int_types< my_pointer_size >::int_type int_type
#define STXXL_BEGIN_NAMESPACE
#define STXXL_VERBOSE1(x)
std::list< block_type * >::iterator free_blocks_iterator
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
unsigned_type size() const
Returns number of owned blocks.
unsigned_type resize(unsigned_type new_size)
Resizes size of the pool.
std::pair< block_type *, request_ptr > busy_entry
request_ptr read(block_type *&block, bid_type bid)
Reads block. If this block is cached block is not read but passed from the cache. ...
prefetch_pool(unsigned_type init_size=1)
Constructs pool.
#define STXXL_END_NAMESPACE
compat_hash_map< bid_type, busy_entry, bid_hash >::result hash_map_type