| … | … | @@ -163,8 +163,7 @@ class async_buffer |
| 163 | 163 | void insert(Element&&); |
| 164 | 164 | void flush(); |
| 165 | 165 | void barrier(void); |
| 166 | template<typename Factory> | |
| 167 | void barrier(Factory&& make_element); | |
| 166 | void barrier(const Element&); | |
| 168 | 167 | |
| 169 | 168 | void set_watermarks(size_t, size_t); |
| 170 | 169 | void stall(bool); |
| … | … | @@ -437,23 +436,18 @@ void async_buffer<Writer, Element>::barrier() |
| 437 | 436 | drain(); |
| 438 | 437 | } |
| 439 | 438 | |
| 440 | /// Barrier that ensures every worker processes a provided element. | |
| 439 | /// Barrier that ensures every worker processes the given element. | |
| 441 | 440 | /// This first drains existing work queues, then gives each worker |
| 442 | /// an element provided by the factory. It then waits for all | |
| 443 | /// workers to complete. This guarantees that every worker has run | |
| 444 | /// at least once. | |
| 445 | /// | |
| 446 | /// The factory callable is invoked once per worker thread to create | |
| 447 | /// a unique element. Since the async_buffer is deduplicating for | |
| 448 | /// work elements, each element must be distinct. | |
| 441 | /// a copy of `elt` for processing. It then waits for all workers | |
| 442 | /// to complete. This guarantees that every worker has run at least | |
| 443 | /// once. | |
| 449 | 444 | /// |
| 450 | 445 | /// The intended use case for this function are systems that have |
| 451 | 446 | /// workers that do caching or lazy initialization or implement |
| 452 | 447 | /// other actions that require synchronization that the default |
| 453 | 448 | /// `barrier(void)` would miss. |
| 454 | 449 | template<typename Writer, typename Element> |
| 455 | template<typename Factory> | |
| 456 | void async_buffer<Writer, Element>::barrier(Factory&& make_element) | |
| 450 | void async_buffer<Writer, Element>::barrier(const Element& elt) | |
| 457 | 451 | { |
| 458 | 452 | std::unique_lock<std::mutex> lock(_enqueue_mutex); |
| 459 | 453 | |
| … | … | @@ -467,7 +461,7 @@ void async_buffer<Writer, Element>::barrier(Factory&& make_element) |
| 467 | 461 | |
| 468 | 462 | // Enqueue one element for each thread. |
| 469 | 463 | for (unsigned int i = 0; i < _thread_count; i++) |
| 470 | do_insert(make_element()); | |
| 464 | do_insert(elt); | |
| 471 | 465 | |
| 472 | 466 | // Wait for all threads to complete their barrier work |
| 473 | 467 | completion.wait(); |
| … | … | @@ -135,8 +135,7 @@ class async_caller |
| 135 | 135 | void enqueue(Element&&); |
| 136 | 136 | void flush_queue(); |
| 137 | 137 | void barrier(void); |
| 138 | template<typename Factory> | |
| 139 | void barrier(Factory&& make_element); | |
| 138 | void barrier(const Element&); | |
| 140 | 139 | |
| 141 | 140 | void set_watermarks(size_t, size_t); |
| 142 | 141 | |
| … | … | @@ -350,22 +349,18 @@ void async_caller<Writer, Element>::barrier() |
| 350 | 349 | drain(); |
| 351 | 350 | } |
| 352 | 351 | |
| 353 | /// Barrier that ensures every worker processes an element. | |
| 352 | /// Barrier that ensures every worker processes the given element. | |
| 354 | 353 | /// This first drains existing work queues, then gives each worker |
| 355 | /// an element provided by the factory. It then waits for all | |
| 356 | /// workers to complete. This guarantees that every worker has run | |
| 357 | /// at least once. | |
| 358 | /// | |
| 359 | /// The factory callable is invoked once per worker thread to create | |
| 360 | /// an element. | |
| 354 | /// a copy of `elt` for processing. It then waits for all workers | |
| 355 | /// to complete. This guarantees that every worker has run at least | |
| 356 | /// once. | |
| 361 | 357 | /// |
| 362 | 358 | /// The intended use case for this function are systems that have |
| 363 | 359 | /// workers that do caching or lazy initialization or implement |
| 364 | 360 | /// other actions that require synchronization that the default |
| 365 | 361 | /// `barrier(void)` would miss. |
| 366 | 362 | template<typename Writer, typename Element> |
| 367 | template<typename Factory> | |
| 368 | void async_caller<Writer, Element>::barrier(Factory&& make_element) | |
| 363 | void async_caller<Writer, Element>::barrier(const Element& elt) | |
| 369 | 364 | { |
| 370 | 365 | std::unique_lock<std::mutex> lock(_enqueue_mutex); |
| 371 | 366 | |
| … | … | @@ -381,7 +376,7 @@ void async_caller<Writer, Element>::barrier(Factory&& make_element) |
| 381 | 376 | for (unsigned int i = 0; i < _thread_count; i++) |
| 382 | 377 | { |
| 383 | 378 | _pending ++; |
| 384 | _store_queue.push(make_element()); | |
| 379 | _store_queue.push(elt); | |
| 385 | 380 | _item_count++; |
| 386 | 381 | } |
| 387 | 382 |