KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PRIORITY_THREAD_POOL_TASK< ContainerT > Class Template Referenceabstract

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 ()
 
void SetReporter (PROGRESS_REPORTER *aReporter)
 
void 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 comparePriority() implemented by the derived class.
 

Protected Attributes

PROGRESS_REPORTERm_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
 

Detailed Description

template<typename ContainerT>
class PRIORITY_THREAD_POOL_TASK< ContainerT >

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.

Member Typedef Documentation

◆ ItemT

template<typename ContainerT>
using PRIORITY_THREAD_POOL_TASK< ContainerT >::ItemT = typename ContainerT::value_type

Definition at line 36 of file priority_thread_pool_task.h.

Constructor & Destructor Documentation

◆ PRIORITY_THREAD_POOL_TASK()

template<typename ContainerT>
PRIORITY_THREAD_POOL_TASK< ContainerT >::PRIORITY_THREAD_POOL_TASK ( )
inline

Definition at line 38 of file priority_thread_pool_task.h.

References m_highestPriority, m_reporter, and m_reporterInterval.

Member Function Documentation

◆ computePriorityKey()

template<typename ContainerT>
virtual int PRIORITY_THREAD_POOL_TASK< ContainerT >::computePriorityKey ( const ItemT & aItem) const
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().

◆ Execute()

template<typename ContainerT>
void PRIORITY_THREAD_POOL_TASK< ContainerT >::Execute ( ContainerT & aItems)
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 comparePriority() implemented by the derived class.

Definition at line 52 of file priority_thread_pool_task.h.

References computePriorityKey(), GetKiCadThreadPool(), m_highestPriority, m_reporter, m_reporterInterval, and tp.

Referenced by ALLEGRO::BOARD_BUILDER::ZONE_FILL_HANDLER::ProcessPolygons().

◆ SetReporter()

template<typename ContainerT>
void PRIORITY_THREAD_POOL_TASK< ContainerT >::SetReporter ( PROGRESS_REPORTER * aReporter)
inline

Definition at line 45 of file priority_thread_pool_task.h.

References m_reporter.

◆ task()

template<typename ContainerT>
virtual size_t PRIORITY_THREAD_POOL_TASK< ContainerT >::task ( ItemT & item)
privatepure virtual

Process one item in the thread pool.

Return the number of items processed.

Member Data Documentation

◆ m_highestPriority

template<typename ContainerT>
BS::priority_t PRIORITY_THREAD_POOL_TASK< ContainerT >::m_highestPriority
private

Definition at line 129 of file priority_thread_pool_task.h.

Referenced by Execute(), and PRIORITY_THREAD_POOL_TASK().

◆ m_reporter

template<typename ContainerT>
PROGRESS_REPORTER* PRIORITY_THREAD_POOL_TASK< ContainerT >::m_reporter
protected

Definition at line 105 of file priority_thread_pool_task.h.

Referenced by Execute(), PRIORITY_THREAD_POOL_TASK(), and SetReporter().

◆ m_reporterInterval

template<typename ContainerT>
std::chrono::milliseconds PRIORITY_THREAD_POOL_TASK< ContainerT >::m_reporterInterval
private

Definition at line 130 of file priority_thread_pool_task.h.

Referenced by Execute(), and PRIORITY_THREAD_POOL_TASK().


The documentation for this class was generated from the following file: