15 #ifndef STXXL_MNG_BLOCK_PREFETCHER_HEADER
16 #define STXXL_MNG_BLOCK_PREFETCHER_HEADER
38 : switch_(_switch), on_compl(on_compl)
54 template <
typename BlockType,
typename B
idIteratorType>
61 typedef typename block_type::bid_type
bid_type;
90 completed[iblock].wait_for_on();
92 STXXL_VERBOSE1(
"block_prefetcher: finished waiting block " << iblock);
93 int_type ibuffer = pref_buffer[iblock];
95 assert(ibuffer >= 0 && ibuffer < nreadblocks);
96 return (read_buffers + ibuffer);
113 : consume_seq_begin(_cons_begin),
114 consume_seq_end(_cons_end),
115 seq_length(_cons_end - _cons_begin),
116 prefetch_seq(_pref_seq),
119 nreadblocks(nextread),
120 do_after_fetch(do_after_fetch)
123 STXXL_VERBOSE1(
"block_prefetcher: _prefetch_buf_size=" << _prefetch_buf_size);
124 assert(seq_length > 0);
125 assert(_prefetch_buf_size > 0);
129 read_bids =
new bid_type[nreadblocks];
130 pref_buffer =
new int_type[seq_length];
132 std::fill(pref_buffer, pref_buffer + seq_length, -1);
136 for (i = 0; i < nreadblocks; ++i)
138 assert(prefetch_seq[i] <
int_type(seq_length));
139 assert(prefetch_seq[i] >= 0);
140 read_bids[i] = *(consume_seq_begin + prefetch_seq[i]);
142 " prefetch_seq[" << i <<
"]=" << prefetch_seq[i] <<
143 " @ " << &read_buffers[i] <<
144 " @ " << read_bids[i]);
145 read_reqs[i] = read_buffers[i].read(
148 pref_buffer[prefetch_seq[i]] = i;
156 return wait(nextconsume++);
165 int_type ibuffer = buffer - read_buffers;
166 STXXL_VERBOSE1(
"block_prefetcher: buffer " << ibuffer <<
" consumed");
167 if (read_reqs[ibuffer].valid())
168 read_reqs[ibuffer]->wait();
170 read_reqs[ibuffer] = NULL;
172 if (nextread < seq_length)
174 assert(ibuffer >= 0 && ibuffer < nreadblocks);
175 int_type next_2_prefetch = prefetch_seq[nextread++];
176 STXXL_VERBOSE1(
"block_prefetcher: prefetching block " << next_2_prefetch);
178 assert((next_2_prefetch <
int_type(seq_length)) && (next_2_prefetch >= 0));
179 assert(!completed[next_2_prefetch].is_on());
181 pref_buffer[next_2_prefetch] = ibuffer;
182 read_bids[ibuffer] = *(consume_seq_begin + next_2_prefetch);
183 read_reqs[ibuffer] = read_buffers[ibuffer].read(
189 if (nextconsume >= seq_length)
192 buffer = wait(nextconsume++);
201 return nextconsume >= seq_length;
213 for (
int_type i = 0; i < nreadblocks; ++i)
214 if (read_reqs[i].valid())
215 read_reqs[i]->wait();
220 delete[] pref_buffer;
221 delete[] read_buffers;
229 #endif // !STXXL_MNG_BLOCK_PREFETCHER_HEADER
Completion handler class (Loki-style).
const Type & STXXL_MIN(const Type &a, const Type &b)
block_type * read_buffers
bool empty() const
No more consumable blocks available, but can't delete the prefetcher, because not all blocks may have...
block_type::bid_type bid_type
completion_handler on_compl
bid_iterator_type consume_seq_end
set_switch_handler(onoff_switch &_switch, const completion_handler &on_compl)
BidIteratorType bid_iterator_type
Encapsulates asynchronous prefetching engine.
bid_iterator_type consume_seq_begin
block_prefetcher(bid_iterator_type _cons_begin, bid_iterator_type _cons_end, int_type *_pref_seq, int_type _prefetch_buf_size, completion_handler do_after_fetch=completion_handler())
Constructs an object and immediately starts prefetching.
choose_int_types< my_pointer_size >::int_type int_type
#define STXXL_BEGIN_NAMESPACE
unsigned_type nextconsume
unsigned_type pos() const
Index of the next element in the consume sequence.
#define STXXL_VERBOSE1(x)
block_type * wait(int_type iblock)
bool block_consumed(block_type *&buffer)
Exchanges buffers between prefetcher and application.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
block_type * pull_block()
Pulls next unconsumed block from the consumption sequence.
Request object encapsulating basic properties like file and offset.
completion_handler do_after_fetch
#define STXXL_END_NAMESPACE
const int_type nreadblocks
~block_prefetcher()
Frees used memory.