pcbnew: Parallelize initial board triangulation

Triangulation of zones can be time consuming for large boards.  This
adds a std::thread implementation of parallel zone loading to speed this
process on multi-core machines.

(cherry picked from commit a04ef37d67)
This commit is contained in:
Seth Hillbrand 2018-09-12 02:22:01 -07:00
parent 4560d4ef69
commit b4fc7575a5
1 changed files with 24 additions and 4 deletions

View File

@ -140,13 +140,25 @@ PCB_DRAW_PANEL_GAL::~PCB_DRAW_PANEL_GAL()
void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard )
{
m_view->Clear();
// Load zones
for( auto zone : aBoard->Zones() )
auto zones = aBoard->Zones();
std::atomic<size_t> next( 0 );
std::atomic<size_t> count_done( 0 );
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
{
zone->CacheTriangulation();
m_view->Add( zone );
std::thread t = std::thread( [ &count_done, &next, &zones ]( )
{
for( size_t i = next.fetch_add( 1 ); i < zones.size(); i = next.fetch_add( 1 ) )
zones[i]->CacheTriangulation();
count_done++;
} );
t.detach();
}
// Load drawings
@ -171,6 +183,14 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard )
m_view->Add( aBoard->GetMARKER( marker_idx ) );
}
// Finalize the triangulation threads
while( count_done < parallelThreadCount )
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
// Load zones
for( auto zone : aBoard->Zones() )
m_view->Add( zone );
// Ratsnest
m_ratsnest.reset( new KIGFX::RATSNEST_VIEWITEM( aBoard->GetConnectivity() ) );
m_view->Add( m_ratsnest.get() );