14 #ifndef STXXL_MNG_PREFETCH_POOL_HEADER
15 #define STXXL_MNG_PREFETCH_POOL_HEADER
29 template <
class BlockType>
34 typedef typename block_type::bid_type
bid_type;
41 size_t result = size_t(bid.storage) +
42 size_t(bid.offset & 0xffffffff) + size_t(bid.offset >> 32);
48 return (a.storage < b.storage) || (a.storage == b.storage && a.offset < b.offset);
75 for ( ; i < init_size; ++i)
89 while (!free_blocks.empty())
91 delete free_blocks.back();
92 free_blocks.pop_back();
98 for ( ; i2 != busy_blocks.end(); ++i2)
100 i2->second.second->wait();
101 delete i2->second.first;
110 {
return free_blocks_size + busy_blocks.size(); }
122 if (in_prefetching(bid)) {
123 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" was already cached");
127 if (free_blocks_size)
131 free_blocks.pop_back();
132 STXXL_VERBOSE2(
"prefetch_pool::hint bid=" << bid <<
" => prefetching");
137 STXXL_VERBOSE2(
"prefetch_pool::hint bid=" << bid <<
" => no free blocks for prefetching");
144 if (in_prefetching(bid)) {
145 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" was already cached");
149 if (free_blocks_size)
153 free_blocks.pop_back();
157 STXXL_VERBOSE1(
"prefetch_pool::hint2 bid=" << bid <<
" was in write cache at " << wp_request.first);
158 assert(wp_request.first != 0);
160 busy_blocks[bid] = wp_request;
163 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" => prefetching");
168 STXXL_VERBOSE2(
"prefetch_pool::hint2 bid=" << bid <<
" => no free blocks for prefetching");
175 if (cache_el == busy_blocks.end())
180 if (cache_el->second.second->get_type() == request::READ)
181 cache_el->second.second->cancel();
183 cache_el->second.second->wait();
185 free_blocks.push_back(cache_el->second.first);
186 busy_blocks.erase(cache_el);
192 return (busy_blocks.find(bid) != busy_blocks.end());
204 if (cache_el == busy_blocks.end())
207 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => no copy in cache, retrieving to " << block);
208 return block->read(bid);
212 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => copy in cache exists");
214 free_blocks.push_back(block);
215 block = cache_el->second.first;
217 busy_blocks.erase(cache_el);
225 if (cache_el != busy_blocks.end())
228 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => copy in cache exists");
230 free_blocks.push_back(block);
231 block = cache_el->second.first;
233 busy_blocks.erase(cache_el);
241 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" was in write cache at " << wp_request.first);
242 assert(wp_request.first != 0);
244 block = wp_request.first;
245 return wp_request.second;
249 STXXL_VERBOSE1(
"prefetch_pool::read bid=" << bid <<
" => no copy in cache, retrieving to " << block);
250 return block->read(bid);
264 free_blocks_size += diff;
272 while (diff < 0 && free_blocks_size > 0)
276 delete free_blocks.back();
277 free_blocks.pop_back();
289 template <
class BlockType>
298 #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