| … | … | @@ -150,7 +150,7 @@ class async_buffer |
| 150 | 150 | void stop_writer_threads(); |
| 151 | 151 | void write_loop(); |
| 152 | 152 | |
| 153 | | void do_insert(const Element&); |
| 153 | void do_insert(Element&&); |
| 154 | 154 | void drain(); |
| 155 | 155 | |
| 156 | 156 | public: |
| … | … | @@ -159,7 +159,8 @@ class async_buffer |
| 159 | 159 | |
| 160 | 160 | async_buffer(Writer*, void (Writer::*)(const Element&), int nthreads=4); |
| 161 | 161 | ~async_buffer(); |
| 162 | | void insert(const Element&); |
| 162 | void insert(const Element& elt) { insert(Element(elt)); } |
| 163 | void insert(Element&&); |
| 163 | 164 | void flush(); |
| 164 | 165 | void barrier(void); |
| 165 | 166 | template<typename Factory> |
| … | … | @@ -526,10 +527,10 @@ void async_buffer<Writer, Element>::write_loop() |
| 526 | 527 | |
| 527 | 528 | /// Insert, no matter what. Private, unsafe for external use. |
| 528 | 529 | template<typename Writer, typename Element> |
| 529 | | void async_buffer<Writer, Element>::do_insert(const Element& elt) |
| 530 | void async_buffer<Writer, Element>::do_insert(Element&& elt) |
| 530 | 531 | { |
| 531 | 532 | _pending ++; |
| 532 | | bool inserted = _store_set.insert(elt); |
| 533 | bool inserted = _store_set.insert(std::move(elt)); |
| 533 | 534 | _item_count++; |
| 534 | 535 | if (not inserted) |
| 535 | 536 | { |
| … | … | @@ -545,7 +546,7 @@ void async_buffer<Writer, Element>::do_insert(const Element& elt) |
| 545 | 546 | * mostly drained... |
| 546 | 547 | */ |
| 547 | 548 | template<typename Writer, typename Element> |
| 548 | | void async_buffer<Writer, Element>::insert(const Element& elt) |
| 549 | void async_buffer<Writer, Element>::insert(Element&& elt) |
| 549 | 550 | { |
| 550 | 551 | // Sanity checks. |
| 551 | 552 | if (_stopping_writers) |
| … | … | @@ -574,7 +575,7 @@ void async_buffer<Writer, Element>::insert(const Element& elt) |
| 574 | 575 | { |
| 575 | 576 | if (th.get_id() == tid) |
| 576 | 577 | { |
| 577 | | do_insert(elt); |
| 578 | do_insert(std::move(elt)); |
| 578 | 579 | return; |
| 579 | 580 | } |
| 580 | 581 | } |
| … | … | @@ -585,7 +586,7 @@ void async_buffer<Writer, Element>::insert(const Element& elt) |
| 585 | 586 | // do need to use a lock for that. |
| 586 | 587 | { |
| 587 | 588 | std::unique_lock<std::mutex> lock(_enqueue_mutex); |
| 588 | | do_insert(elt); |
| 589 | do_insert(std::move(elt)); |
| 589 | 590 | } |
| 590 | 591 | |
| 591 | 592 | // If the writer threads are falling behind, mitigate. |