Browse Source

pcbnew: now PROGRESS_REPORTER should work in multi-threaded context under Windows...

pull/5/merge
Tomasz Włostowski 8 years ago
parent
commit
7ad436c7aa
  1. 23
      common/widgets/progress_reporter.cpp
  2. 7
      include/widgets/progress_reporter.h
  3. 15
      pcbnew/connectivity_algo.cpp
  4. 33
      pcbnew/zone_filler.cpp

23
common/widgets/progress_reporter.cpp

@ -28,15 +28,14 @@
PROGRESS_REPORTER::PROGRESS_REPORTER( int aNumPhases ) : PROGRESS_REPORTER::PROGRESS_REPORTER( int aNumPhases ) :
m_phase( 0 ), m_phase( 0 ),
m_progress( 0 ),
m_numPhases( aNumPhases ), m_numPhases( aNumPhases ),
m_progress( 0 ),
m_maxProgress( 1 ) m_maxProgress( 1 )
{ {
}; };
void PROGRESS_REPORTER::BeginPhase( int aPhase ) void PROGRESS_REPORTER::BeginPhase( int aPhase )
{ {
std::lock_guard<std::mutex> guard( m_lock );
m_phase = aPhase; m_phase = aPhase;
m_progress = 0; m_progress = 0;
updateUI(); updateUI();
@ -44,7 +43,6 @@ void PROGRESS_REPORTER::BeginPhase( int aPhase )
void PROGRESS_REPORTER::AdvancePhase( ) void PROGRESS_REPORTER::AdvancePhase( )
{ {
std::lock_guard<std::mutex> guard( m_lock );
m_phase++; m_phase++;
m_progress = 0; m_progress = 0;
updateUI(); updateUI();
@ -52,28 +50,24 @@ void PROGRESS_REPORTER::AdvancePhase( )
void PROGRESS_REPORTER::Report( const wxString& aMessage ) void PROGRESS_REPORTER::Report( const wxString& aMessage )
{ {
std::lock_guard<std::mutex> guard( m_lock );
m_rptMessage = aMessage; m_rptMessage = aMessage;
updateUI(); updateUI();
} }
void PROGRESS_REPORTER::SetMaxProgress ( int aMaxProgress ) void PROGRESS_REPORTER::SetMaxProgress ( int aMaxProgress )
{ {
std::lock_guard<std::mutex> guard( m_lock );
m_maxProgress = aMaxProgress; m_maxProgress = aMaxProgress;
updateUI(); updateUI();
} }
void PROGRESS_REPORTER::AdvanceProgress( ) void PROGRESS_REPORTER::AdvanceProgress( )
{ {
std::lock_guard<std::mutex> guard( m_lock );
m_progress++; m_progress++;
updateUI();
} }
int PROGRESS_REPORTER::currentProgress() const int PROGRESS_REPORTER::currentProgress() const
{ {
double current = (1.0 / (double)m_numPhases) * ( (double) m_phase + ( (double) m_progress / (double) m_maxProgress ) );
double current = (1.0 / (double)m_numPhases) * ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
return (int)(current * 1000); return (int)(current * 1000);
} }
@ -102,5 +96,16 @@ void WX_PROGRESS_REPORTER::updateUI()
cur = 0; cur = 0;
SetRange( 1000 ); SetRange( 1000 );
Update( cur, m_rptMessage );
wxProgressDialog::Update( cur, m_rptMessage );
}
void PROGRESS_REPORTER::KeepRefreshing()
{
while ( m_progress < m_maxProgress && m_maxProgress > 0)
{
updateUI();
#ifdef USE_OPENMP
wxMilliSleep(10);
#endif
}
} }

7
include/widgets/progress_reporter.h

@ -26,6 +26,7 @@
#define __PROGRESS_REPORTER #define __PROGRESS_REPORTER
#include <mutex> #include <mutex>
#include <atomic>
#include <wx/progdlg.h> #include <wx/progdlg.h>
@ -42,6 +43,8 @@ class PROGRESS_REPORTER
void SetMaxProgress ( int aMaxProgress ); void SetMaxProgress ( int aMaxProgress );
void AdvanceProgress( ); void AdvanceProgress( );
void KeepRefreshing();
protected: protected:
int currentProgress() const; int currentProgress() const;
@ -50,10 +53,8 @@ class PROGRESS_REPORTER
wxString m_rptMessage; wxString m_rptMessage;
int m_phase; int m_phase;
int m_numPhases; int m_numPhases;
int m_progress;
std::atomic_int m_progress;
int m_maxProgress; int m_maxProgress;
std::mutex m_lock;
}; };
class WX_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxProgressDialog class WX_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxProgressDialog

15
pcbnew/connectivity_algo.cpp

@ -521,7 +521,19 @@ void CN_CONNECTIVITY_ALGO::searchConnections( bool aIncludeZones )
} }
#ifdef USE_OPENMP #ifdef USE_OPENMP
#pragma omp parallel for schedule(dynamic)
#pragma omp parallel
#endif
{
#ifdef USE_OPENMP
#pragma omp master
#endif
if (m_progressReporter)
{
m_progressReporter->KeepRefreshing();
}
#ifdef USE_OPENMP
#pragma omp for schedule(dynamic)
#endif #endif
for(int i = 0; i < m_zoneList.Size(); i++ ) for(int i = 0; i < m_zoneList.Size(); i++ )
{ {
@ -548,6 +560,7 @@ void CN_CONNECTIVITY_ALGO::searchConnections( bool aIncludeZones )
} }
} }
} }
}
m_zoneList.ClearDirtyFlags(); m_zoneList.ClearDirtyFlags();
} }

33
pcbnew/zone_filler.cpp

@ -126,8 +126,21 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
m_progressReporter->SetMaxProgress( toFill.size() ); m_progressReporter->SetMaxProgress( toFill.size() );
} }
#ifdef USE_OPENMP
#pragma omp parallel
#endif
{
#ifdef USE_OPENMP
#pragma omp master
#endif
if( m_progressReporter )
{
m_progressReporter->KeepRefreshing();
}
#ifdef USE_OPENMP #ifdef USE_OPENMP
#pragma omp parallel for schedule(dynamic)
#pragma omp for schedule(dynamic)
#endif #endif
for( int i = 0; i < toFill.size(); i++ ) for( int i = 0; i < toFill.size(); i++ )
{ {
@ -146,6 +159,8 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
} }
} }
}
if( m_progressReporter ) if( m_progressReporter )
{ {
m_progressReporter->AdvancePhase(); m_progressReporter->AdvancePhase();
@ -174,11 +189,21 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
m_progressReporter->Report( _( "Caching polygon triangulations..." ) ); m_progressReporter->Report( _( "Caching polygon triangulations..." ) );
m_progressReporter->SetMaxProgress( toFill.size() ); m_progressReporter->SetMaxProgress( toFill.size() );
} }
#ifdef USE_OPENMP #ifdef USE_OPENMP
#pragma omp parallel for schedule(dynamic)
#pragma omp parallel
#endif
{
#ifdef USE_OPENMP
#pragma omp master
#endif #endif
if( m_progressReporter )
{
m_progressReporter->KeepRefreshing();
}
#ifdef USE_OPENMP
#pragma omp for schedule(dynamic)
#endif
for( int i = 0; i < toFill.size(); i++ ) for( int i = 0; i < toFill.size(); i++ )
{ {
if( m_progressReporter ) if( m_progressReporter )
@ -188,7 +213,7 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
toFill[i].m_zone->CacheTriangulation(); toFill[i].m_zone->CacheTriangulation();
} }
}
if( m_progressReporter ) if( m_progressReporter )
{ {
m_progressReporter->AdvancePhase(); m_progressReporter->AdvancePhase();

Loading…
Cancel
Save