14 #ifndef STXXL_MNG_WRITE_POOL_HEADER
15 #define STXXL_MNG_WRITE_POOL_HEADER
23 #define STXXL_VERBOSE_WPOOL(msg) STXXL_VERBOSE1("write_pool[" << static_cast<void*>(this) << "]" << msg)
31 template <
class BlockType>
36 typedef typename block_type::bid_type
bid_type;
48 : block(bl), req(r), bid(bi) { }
83 " busy_blocks.size()=" << busy_blocks.size());
84 while (!free_blocks.empty())
87 delete free_blocks.back();
88 free_blocks.pop_back();
96 if (free_blocks.empty())
121 if (i2->bid == bid) {
122 assert(i2->block != block);
132 busy_blocks.push_back(
busy_entry(block, result, bid));
142 if (!free_blocks.empty())
145 STXXL_VERBOSE_WPOOL(
"::steal : " << free_blocks.size() <<
" free blocks available, serve block=" << p);
146 free_blocks.pop_back();
151 assert(completed != busy_blocks.end());
152 assert(completed->req->poll());
154 busy_blocks.erase(completed);
189 for ( ; i2 != busy_blocks.end(); ++i2)
210 for ( ; i2 != busy_blocks.end(); ++i2)
216 busy_blocks.erase(i2);
233 busy_blocks.erase(i2);
237 return std::pair<block_type*, request_ptr>(blk, req);
248 free_blocks.push_back(block);
257 while (cur != busy_blocks.end())
259 if (cur->req->poll())
261 free_blocks.push_back(cur->block);
262 cur = busy_blocks.erase(cur);
269 " are completed out of " << busy_blocks.size() + cnt <<
" busy blocks");
279 template <
class BlockType>
288 #endif // !STXXL_MNG_WRITE_POOL_HEADER
bool has_request(bid_type bid)
void add(block_type *&block)
block_type * steal()
Take out a block from the pool.
std::list< busy_entry >::iterator busy_blocks_iterator
write_pool(unsigned_type init_size=1)
Constructs pool.
#define STXXL_VERBOSE_WPOOL(msg)
std::list< busy_entry > busy_blocks
#define STXXL_DEPRECATED(x)
void resize(unsigned_type new_size)
Resizes size of the pool.
request_ptr get_request(bid_type bid)
std::pair< block_type *, request_ptr > steal_request(bid_type bid)
Implements dynamically resizable buffered writing pool.
block_type::bid_type bid_type
counting_ptr< request > request_ptr
A reference counting pointer for request.
choose_int_types< my_pointer_size >::int_type int_type
std::list< block_type * > free_blocks
#define STXXL_BEGIN_NAMESPACE
block_type * steal(bid_type bid)
request_ptr write(block_type *&block, bid_type bid)
Passes a block to the pool for writing.
std::list< block_type * >::iterator free_blocks_iterator
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
RequestIterator wait_any(RequestIterator reqs_begin, RequestIterator reqs_end)
Suspends calling thread until any of requests is completed.
busy_entry(const busy_entry &a)
unsigned_type size() const
Returns number of owned blocks.
busy_entry(block_type *&bl, request_ptr &r, bid_type &bi)
#define STXXL_END_NAMESPACE
~write_pool()
Waits for completion of all ongoing write requests and frees memory.
void swap(write_pool &obj)