14 #ifndef FOXXLL_MNG_WRITE_POOL_HEADER 15 #define FOXXLL_MNG_WRITE_POOL_HEADER 25 #include <foxxll/config.hpp> 28 #define FOXXLL_VERBOSE_WPOOL(msg) \ 29 TLX_LOG << "write_pool[" << static_cast<void*>(this) << "]" << msg 37 template <
class BlockType>
40 constexpr
static bool debug =
false;
44 using bid_type =
typename block_type::bid_type;
56 : block(bl), req(r), bid(bi) { }
74 for (
size_t i = 0; i < init_size; ++i)
96 "::~write_pool free_blocks.size()=" << free_blocks.size() <<
97 " busy_blocks.size()=" << busy_blocks.size()
99 while (!free_blocks.empty())
102 delete free_blocks.back();
103 free_blocks.pop_back();
111 if (free_blocks.empty())
123 size_t size()
const {
return free_blocks.size() + busy_blocks.size(); }
136 if (i2->bid == bid) {
137 assert(i2->block != block);
147 busy_blocks.push_back(
busy_entry(block, result, bid));
157 if (!free_blocks.empty())
160 FOXXLL_VERBOSE_WPOOL(
"::steal : " << free_blocks.size() <<
" free blocks available, serve block=" << p);
161 free_blocks.pop_back();
166 assert(completed != busy_blocks.end());
167 assert(completed->req->poll());
169 busy_blocks.erase(completed);
179 int64_t diff = int64_t(new_size) - int64_t(
size());
215 busy_blocks.erase(i2);
219 return std::pair<block_type*, request_ptr>(blk,
req);
224 return std::pair<block_type*, request_ptr>(
nullptr,
request_ptr());
230 free_blocks.push_back(block);
239 while (cur != busy_blocks.end())
241 if (cur->req->poll())
243 free_blocks.push_back(cur->block);
244 cur = busy_blocks.erase(cur);
251 "::check_all_busy : " << cnt <<
252 " are completed out of " << busy_blocks.size() + cnt <<
" busy blocks" 257 #undef FOXXLL_VERBOSE_WPOOL 265 template <
class BlockType>
274 #endif // !FOXXLL_MNG_WRITE_POOL_HEADER
#define FOXXLL_VERBOSE_WPOOL(msg)
bool has_request(bid_type bid)
typename std::list< block_type * >::iterator free_blocks_iterator
tlx::counting_ptr< request > request_ptr
A reference counting pointer for request.
Implements dynamically resizable buffered writing pool.
~write_pool()
Waits for completion of all ongoing write requests and frees memory.
void resize(size_t new_size)
static constexpr bool debug
write_pool & operator=(const write_pool &)=delete
non-copyable: delete assignment operator
std::pair< block_type *, request_ptr > steal_request(bid_type bid)
std::list< block_type * > free_blocks
busy_entry(const busy_entry &a)
typename block_type::bid_type bid_type
std::list< busy_entry > busy_blocks
High-performance smart pointer used as a wrapping reference counting pointer.
void add(block_type *&block)
RequestIterator wait_any(RequestIterator reqs_begin, RequestIterator reqs_end)
write_pool(size_t init_size=1)
size_t size() const
Returns number of owned blocks.
request_ptr write(block_type *&block, bid_type bid)
void swap(write_pool &obj)
busy_entry(block_type *&bl, request_ptr &r, bid_type &bi)
typename std::list< busy_entry >::iterator busy_blocks_iterator