@@ -80,62 +80,72 @@ class TrackAnalysisScheduler : public QObject {
8080 // that runs the TrackAnalysisScheduler.
8181 class Worker {
8282 public:
83- explicit Worker (AnalyzerThread::Pointer thread = AnalyzerThread::NullPointer())
84- : m_thread (std::move(thread )),
85- m_analyzerProgress(kAnalyzerProgressUnknown ) {
83+ explicit Worker (AnalyzerThread::Pointer pThread = AnalyzerThread::NullPointer())
84+ : m_pThread (std::move(pThread )),
85+ m_analyzerProgress(kAnalyzerProgressUnknown ) {
8686 }
8787 Worker (const Worker&) = delete ;
8888 Worker (Worker&&) = default ;
8989
90- operator bool () const {
91- return static_cast <bool >(m_thread);
90+ ~Worker () {
91+ if (m_pThread) {
92+ m_pThread->stop ();
93+ bool success = m_pThread->wait (5000 ); // 5 s
94+ DEBUG_ASSERT (success);
95+ m_pThread->wait ();
96+ delete m_pThread.release ();
97+ }
98+ }
99+
100+ bool hasThread () const {
101+ return static_cast <bool >(m_pThread);
92102 }
93103
94104 AnalyzerThread* thread () const {
95- DEBUG_ASSERT (m_thread );
96- return m_thread .get ();
105+ DEBUG_ASSERT (m_pThread );
106+ return m_pThread .get ();
97107 }
98108
99109 AnalyzerProgress analyzerProgress () const {
100110 return m_analyzerProgress;
101111 }
102112
103113 bool submitNextTrack (const AnalyzerTrack& track) {
104- DEBUG_ASSERT (m_thread );
105- return m_thread ->submitNextTrack (std::move (track));
114+ DEBUG_ASSERT (m_pThread );
115+ return m_pThread ->submitNextTrack (std::move (track));
106116 }
107117
108118 void suspendThread () {
109- if (m_thread ) {
110- m_thread ->suspend ();
119+ if (m_pThread ) {
120+ m_pThread ->suspend ();
111121 }
112122 }
113123
114124 void resumeThread () {
115- if (m_thread ) {
116- m_thread ->resume ();
125+ if (m_pThread ) {
126+ m_pThread ->resume ();
117127 }
118128 }
119129
120130 void stopThread () {
121- if (m_thread ) {
122- m_thread ->stop ();
131+ if (m_pThread ) {
132+ m_pThread ->stop ();
123133 }
124134 }
125135
126136 void onAnalyzerProgress (AnalyzerProgress analyzerProgress) {
127- DEBUG_ASSERT (m_thread );
137+ DEBUG_ASSERT (m_pThread );
128138 m_analyzerProgress = analyzerProgress;
129139 }
130140
131141 void onThreadExit () {
132- DEBUG_ASSERT (m_thread );
133- m_thread .reset ();
142+ DEBUG_ASSERT (m_pThread );
143+ m_pThread .reset ();
134144 m_analyzerProgress = kAnalyzerProgressUnknown ;
135145 }
136146
137147 private:
138- AnalyzerThread::Pointer m_thread ;
148+ AnalyzerThread::Pointer m_pThread ;
139149 AnalyzerProgress m_analyzerProgress;
140150 };
141151
0 commit comments