|
KiCad PCB EDA Suite
|
A helper class to execute tasks on a thread pool in priority order, with progress reporting. More...
#include <priority_thread_pool_task.h>
Public Types | |
| using | ItemT = typename ContainerT::value_type |
Public Member Functions | |
| PRIORITY_THREAD_POOL_TASK () | |
| PRIORITY_THREAD_POOL_TASK (const PRIORITY_THREAD_POOL_TASK &)=delete | |
| PRIORITY_THREAD_POOL_TASK & | operator= (const PRIORITY_THREAD_POOL_TASK &)=delete |
| void | SetReporter (PROGRESS_REPORTER *aReporter) |
| size_t | Execute (ContainerT &aItems) |
| Call this to execute the task on all items in aItems, using the thread pool and dispatching the tasks in order of descending priority as determined by computePriorityKey() implemented by the derived class. | |
Protected Attributes | |
| PROGRESS_REPORTER * | m_reporter |
Private Member Functions | |
| virtual int | computePriorityKey (const ItemT &aItem) const =0 |
| Implement this to compute a priority key for an item. | |
| virtual size_t | task (ItemT &item)=0 |
| Process one item in the thread pool. | |
Private Attributes | |
| BS::priority_t | m_highestPriority |
| std::chrono::milliseconds | m_reporterInterval |
| std::atomic< bool > | m_abort { false } |
| Set when a task throws, so tasks that have not started yet skip their item. | |
A helper class to execute tasks on a thread pool in priority order, with progress reporting.
Definition at line 33 of file priority_thread_pool_task.h.
| using PRIORITY_THREAD_POOL_TASK< ContainerT >::ItemT = typename ContainerT::value_type |
Definition at line 36 of file priority_thread_pool_task.h.
|
inline |
Definition at line 38 of file priority_thread_pool_task.h.
References m_highestPriority, m_reporter, and m_reporterInterval.
Referenced by operator=(), and PRIORITY_THREAD_POOL_TASK().
|
delete |
References PRIORITY_THREAD_POOL_TASK().
|
privatepure virtual |
Implement this to compute a priority key for an item.
Return a number representing priority, where a higher number means higher priority. The actual values returned don't matter, only their relative order.
(A relational a < b comparator would work too, but a unary key lets us compute it once per item in O(n) and then sort indices cheaply, rather than calling it O(n log n) times inside std::sort.)
If you'd like to test the effect of this priority ordering, you can return a constant value to disable sorting, or return the inverse to sort backwards.
Referenced by Execute().
|
inline |
Call this to execute the task on all items in aItems, using the thread pool and dispatching the tasks in order of descending priority as determined by computePriorityKey() implemented by the derived class.
This method blocks until all tasks are complete, and then re-throws the first exception thrown by a task (if any). If a task throws, later tasks that have not started yet are skipped; tasks already running are not interrupted.
It never returns while any task is still queued or running.
| aItems | The container of items to process. |
Definition at line 66 of file priority_thread_pool_task.h.
References computePriorityKey(), GetKiCadThreadPool(), m_abort, m_highestPriority, and tp.
Referenced by ALLEGRO::BOARD_BUILDER::ZONE_FILL_HANDLER::ProcessPolygons().
|
delete |
References PRIORITY_THREAD_POOL_TASK().
|
inline |
Definition at line 49 of file priority_thread_pool_task.h.
References m_reporter.
|
privatepure virtual |
Process one item in the thread pool.
Return the number of items processed.
|
private |
Set when a task throws, so tasks that have not started yet skip their item.
Definition at line 187 of file priority_thread_pool_task.h.
Referenced by Execute().
|
private |
Definition at line 181 of file priority_thread_pool_task.h.
Referenced by Execute(), and PRIORITY_THREAD_POOL_TASK().
|
protected |
Definition at line 157 of file priority_thread_pool_task.h.
Referenced by PRIORITY_THREAD_POOL_TASK(), and SetReporter().
|
private |
Definition at line 182 of file priority_thread_pool_task.h.
Referenced by PRIORITY_THREAD_POOL_TASK().