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)
33 template <
class BlockType>
38 typedef typename block_type::bid_type
bid_type;
50 block(bl), req(r), bid(bi) { }
85 " busy_blocks.size()=" << busy_blocks.size());
86 while (!free_blocks.empty())
89 delete free_blocks.back();
90 free_blocks.pop_back();
98 if (free_blocks.empty())
123 if (i2->bid == bid) {
124 assert(i2->block != block);
134 busy_blocks.push_back(
busy_entry(block, result, bid));
144 if (!free_blocks.empty())
147 STXXL_VERBOSE_WPOOL(
"::steal : " << free_blocks.size() <<
" free blocks available, serve block=" << p);
148 free_blocks.pop_back();
153 assert(completed != busy_blocks.end());
154 assert(completed->req->poll());
156 busy_blocks.erase(completed);
191 for ( ; i2 != busy_blocks.end(); ++i2)
212 for ( ; i2 != busy_blocks.end(); ++i2)
218 busy_blocks.erase(i2);
235 busy_blocks.erase(i2);
239 return std::pair<block_type*, request_ptr>(blk, req);
250 free_blocks.push_back(block);
259 while (cur != busy_blocks.end())
261 if (cur->req->poll())
263 free_blocks.push_back(cur->block);
264 cur = busy_blocks.erase(cur);
271 " are completed out of " << busy_blocks.size() + cnt <<
" busy blocks");
282 template <
class BlockType>
291 #endif // !STXXL_MNG_WRITE_POOL_HEADER
bool has_request(bid_type bid)
void add(block_type *&block)
virtual ~write_pool()
Waits for completion of all ongoing write requests and frees memory.
block_type * steal()
Take out a block from the pool.
counting_ptr< request > request_ptr
A reference counting pointer for request.
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
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
busy_entry(const busy_entry &a)
request_iterator_ wait_any(request_iterator_ reqs_begin, request_iterator_ reqs_end)
Suspends calling thread until any of requests is completed.
unsigned_type size() const
Returns number of owned blocks.
busy_entry(block_type *&bl, request_ptr &r, bid_type &bi)
#define STXXL_END_NAMESPACE
void swap(write_pool &obj)