14 #ifndef STXXL_CONTAINERS_QUEUE_HEADER
15 #define STXXL_CONTAINERS_QUEUE_HEADER
33 #ifndef STXXL_VERBOSE_QUEUE
34 #define STXXL_VERBOSE_QUEUE STXXL_VERBOSE2
48 template <
class ValueType,
59 block_size = BlockSize
97 D = config::get_instance()->disks_number();
116 pool =
new pool_type(p_pool_size, w_pool_size);
117 init(blocks2prefetch_);
137 init(blocks2prefetch_);
155 init(blocks2prefetch_);
165 std::swap(m_size, obj.
m_size);
167 std::swap(pool, obj.
pool);
174 std::swap(bids, obj.
bids);
175 std::swap(bm, obj.
bm);
182 void init(
int blocks2prefetch_ = -1)
184 if (pool->size_write() < 2) {
185 STXXL_ERRMSG(
"queue: invalid configuration, not enough blocks (" << pool->size_write() <<
186 ") in write pool, at least 2 are needed, resizing to 3");
187 pool->resize_write(3);
190 if (pool->size_write() < 3) {
191 STXXL_MSG(
"queue: inefficient configuration, no blocks for buffered writing available");
194 if (pool->size_prefetch() < 1) {
195 STXXL_MSG(
"queue: inefficient configuration, no blocks for prefetching available");
198 front_block = back_block = pool->steal();
199 back_element = back_block->begin() - 1;
200 front_element = back_block->begin();
201 set_prefetch_aggr(blocks2prefetch_);
214 if (blocks2prefetch_ < 0)
215 blocks2prefetch = pool->size_prefetch();
217 blocks2prefetch = blocks2prefetch_;
223 return blocks2prefetch;
233 if (
UNLIKELY(back_element == back_block->begin() + (block_type::size - 1)))
236 if (front_block == back_block)
241 else if (size() < 2 * block_type::size)
245 assert(bids.empty());
246 size_t gap = front_element - front_block->begin();
248 std::copy(front_element, front_block->end(), front_block->begin());
249 std::copy(back_block->begin(), back_block->begin() + gap, front_block->begin() + (block_type::size - gap));
250 std::copy(back_block->begin() + gap, back_block->end(), back_block->begin());
251 front_element -= gap;
266 bm->new_block(alloc_strategy, newbid, alloc_count++);
269 bids.push_back(newbid);
270 pool->write(back_block, newbid);
271 if (bids.size() <= blocks2prefetch) {
276 back_block = pool->steal();
278 back_element = back_block->begin();
293 if (
UNLIKELY(front_element == front_block->begin() + (block_type::size - 1)))
296 if (back_block == front_block)
300 assert(back_element == front_element);
301 assert(bids.empty());
303 back_element = back_block->begin() - 1;
304 front_element = back_block->begin();
310 if (m_size <= block_type::size)
313 assert(bids.empty());
315 pool->add(front_block);
316 front_block = back_block;
317 front_element = back_block->begin();
322 assert(!bids.empty());
323 request_ptr req = pool->read(front_block, bids.front());
327 for (
unsigned_type i = 0; i < blocks2prefetch && i < bids.size() - 1; ++i)
330 pool->hint(bids[i + 1]);
333 front_element = front_block->begin();
336 bm->delete_block(bids.front());
353 return *back_element;
360 return *back_element;
367 return *front_element;
374 return *front_element;
384 if (front_block != back_block)
385 pool->add(back_block);
386 pool->add(front_block);
394 bm->delete_blocks(bids.begin(), bids.end());
411 return (m_size == 0);
421 #endif // !STXXL_CONTAINERS_QUEUE_HEADER
const value_type & back() const
Returns a const reference at the back of the queue.
queue(pool_type &pool_, int blocks2prefetch_=-1)
Constructs empty queue.
#define STXXL_DEFAULT_BLOCK_SIZE(type)
value_type * back_element
#define STXXL_VERBOSE_QUEUE
unsigned_type alloc_count
unsigned long long int uint64
alloc_strategy_type alloc_strategy
bool empty() const
Returns true if queue is empty.
External FIFO queue container. Introduction to queue container: see STXXL Queue tutorial Design a...
typed_block< block_size, value_type > block_type
#define STXXL_DEFAULT_ALLOC_STRATEGY
read_write_pool< block_type > pool_type
queue(write_pool< block_type > &w_pool, prefetch_pool< block_type > &p_pool, int blocks2prefetch_=-1)
Constructs empty queue.
void push(const value_type &val)
Adds an element in the queue.
#define STXXL_DEPRECATED(x)
Implements dynamically resizable buffered writing pool.
value_type & front()
Returns a mutable reference at the front of the queue.
Implements dynamically resizable prefetching pool.
Block containing elements of fixed length.
AllocStr alloc_strategy_type
const value_type & front() const
Returns a const reference at the front of the queue.
BID< block_size > bid_type
Implements dynamically resizable buffered writing and prefetched reading pool.
choose_int_types< my_pointer_size >::int_type int_type
value_type & back()
Returns a mutable reference at the back of the queue.
value_type * front_element
#define STXXL_BEGIN_NAMESPACE
void init(int blocks2prefetch_=-1)
#define STXXL_VERBOSE1(x)
size_type size() const
Returns the size of the queue.
void set_prefetch_aggr(int_type blocks2prefetch_)
Defines the number of blocks to prefetch (front side). This method should be called whenever the pref...
queue(unsigned_type w_pool_size, unsigned_type p_pool_size, int blocks2prefetch_=-1)
Constructs empty queue with own write and prefetch block pool.
void pop()
Removes element from the queue.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
unsigned_type blocks2prefetch
std::deque< bid_type > bids
queue(int_type D=-1)
Constructs empty queue with own write and prefetch block pool.
unsigned_type get_prefetch_aggr() const
Returns the number of blocks prefetched from the front side.
#define STXXL_END_NAMESPACE