Reinstate multi-threading in zone filler.
This commit is contained in:
parent
919b449595
commit
c77d13292b
|
@ -81,6 +81,8 @@ void ZONE_FILLER::SetProgressReporter( PROGRESS_REPORTER* aReporter )
|
|||
|
||||
void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
||||
{
|
||||
int parallelThreadCount = std::max( ( int )std::thread::hardware_concurrency(), 2 );
|
||||
|
||||
std::vector<CN_ZONE_ISOLATED_ISLAND_LIST> toFill;
|
||||
auto connectivity = m_board->GetConnectivity();
|
||||
|
||||
|
@ -115,10 +117,16 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
m_progressReporter->SetMaxProgress( toFill.size() );
|
||||
}
|
||||
|
||||
m_next = 0;
|
||||
m_count_done = 0;
|
||||
std::thread fillWorker( [ this, toFill ]()
|
||||
std::vector<std::thread> fillWorkers;
|
||||
|
||||
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
||||
{
|
||||
for( unsigned i = 0; i < toFill.size(); i++ )
|
||||
fillWorkers.push_back( std::thread( [ this, toFill ]()
|
||||
{
|
||||
size_t i = m_next.fetch_add( 1 );
|
||||
while( i < toFill.size() )
|
||||
{
|
||||
SHAPE_POLY_SET rawPolys, finalPolys;
|
||||
ZONE_SEGMENT_FILL segFill;
|
||||
|
@ -132,8 +140,10 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
m_progressReporter->AdvanceProgress();
|
||||
|
||||
m_count_done.fetch_add( 1 );
|
||||
i = m_next.fetch_add( 1 );
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
} );
|
||||
|
||||
while( m_count_done.load() < toFill.size() )
|
||||
{
|
||||
|
@ -143,7 +153,8 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
wxMilliSleep( 20 );
|
||||
}
|
||||
|
||||
fillWorker.join();
|
||||
for( size_t ii = 0; ii < fillWorkers.size(); ++ii )
|
||||
fillWorkers[ ii ].join();
|
||||
|
||||
// Now remove insulated copper islands
|
||||
if( m_progressReporter )
|
||||
|
@ -176,10 +187,16 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
m_progressReporter->SetMaxProgress( toFill.size() );
|
||||
}
|
||||
|
||||
m_next = 0;
|
||||
m_count_done = 0;
|
||||
std::thread triangulationWorker( [ this, toFill ]()
|
||||
std::vector<std::thread> triangulationWorkers;
|
||||
|
||||
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
||||
{
|
||||
for( unsigned i = 0; i < toFill.size(); i++ )
|
||||
triangulationWorkers.push_back( std::thread( [ this, toFill ]()
|
||||
{
|
||||
size_t i = m_next.fetch_add( 1 );
|
||||
while( i < toFill.size() )
|
||||
{
|
||||
if( m_progressReporter )
|
||||
m_progressReporter->AdvanceProgress();
|
||||
|
@ -187,8 +204,10 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
toFill[i].m_zone->CacheTriangulation();
|
||||
|
||||
m_count_done.fetch_add( 1 );
|
||||
i = m_next.fetch_add( 1 );
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
} );
|
||||
|
||||
while( m_count_done.load() < toFill.size() )
|
||||
{
|
||||
|
@ -198,7 +217,8 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
wxMilliSleep( 10 );
|
||||
}
|
||||
|
||||
triangulationWorker.join();
|
||||
for( size_t ii = 0; ii < triangulationWorkers.size(); ++ii )
|
||||
triangulationWorkers[ ii ].join();
|
||||
|
||||
// If some zones must be filled by segments, create the filling segments
|
||||
// (note, this is a outdated option, but it exists)
|
||||
|
@ -219,7 +239,7 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
|
|||
m_progressReporter->SetMaxProgress( zones_to_fill_count );
|
||||
}
|
||||
|
||||
// TODO: use OPENMP to speedup calculations:
|
||||
// TODO: use thread pool to speedup calculations:
|
||||
for( unsigned i = 0; i < toFill.size(); i++ )
|
||||
{
|
||||
ZONE_CONTAINER* zone = toFill[i].m_zone;
|
||||
|
|
|
@ -119,6 +119,10 @@ private:
|
|||
BOARD* m_board;
|
||||
COMMIT* m_commit;
|
||||
PROGRESS_REPORTER* m_progressReporter;
|
||||
|
||||
std::atomic_size_t m_next; // An index into the vector of zones to fill.
|
||||
// Used by the variuos parallel thread sets during
|
||||
// fill operations.
|
||||
std::atomic_size_t m_count_done;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue