38
38
39
39
ThreadHandler::ThreadHandler (QObject *parent) :
40
40
QObject(parent)
41
- {
42
- setThreadCount (1 );
43
- }
41
+ {}
44
42
45
43
ThreadHandler::~ThreadHandler ()
46
44
{
@@ -54,7 +52,7 @@ void ThreadHandler::clearFiles()
54
52
mAnalyseWholeProgram = false ;
55
53
mCtuInfo .clear ();
56
54
mAddonsAndTools .clear ();
57
- mSuppressions .clear ();
55
+ mSuppressionsUI .clear ();
58
56
}
59
57
60
58
void ThreadHandler::setFiles (const QStringList &files)
@@ -83,6 +81,14 @@ void ThreadHandler::setCheckFiles(const QStringList& files)
83
81
}
84
82
}
85
83
84
+ void ThreadHandler::setupCheckThread (CheckThread &thread) const
85
+ {
86
+ thread.setAddonsAndTools (mCheckAddonsAndTools );
87
+ thread.setSuppressions (mSuppressionsUI );
88
+ thread.setClangIncludePaths (mClangIncludePaths );
89
+ thread.setSettings (mCheckSettings , mCheckSuppressions );
90
+ }
91
+
86
92
void ThreadHandler::check (const Settings &settings, const std::shared_ptr<Suppressions>& supprs)
87
93
{
88
94
if (mResults .getFileCount () == 0 || mRunningThreadCount > 0 || settings.jobs == 0 ) {
@@ -91,25 +97,25 @@ void ThreadHandler::check(const Settings &settings, const std::shared_ptr<Suppre
91
97
return ;
92
98
}
93
99
94
- setThreadCount (settings.jobs );
100
+ mCheckSettings = settings;
101
+ mCheckSuppressions = supprs;
102
+
103
+ createThreads (mCheckSettings .jobs );
95
104
96
105
mRunningThreadCount = mThreads .size ();
97
106
mRunningThreadCount = std::min (mResults .getFileCount (), mRunningThreadCount );
98
107
99
- QStringList addonsAndTools = mAddonsAndTools ;
100
- for (const std::string& addon: settings .addons ) {
108
+ mCheckAddonsAndTools = mAddonsAndTools ;
109
+ for (const std::string& addon: mCheckSettings .addons ) {
101
110
QString s = QString::fromStdString (addon);
102
- if (!addonsAndTools .contains (s))
103
- addonsAndTools << s;
111
+ if (!mCheckAddonsAndTools .contains (s))
112
+ mCheckAddonsAndTools << s;
104
113
}
105
114
106
115
mCtuInfo .clear ();
107
116
108
117
for (int i = 0 ; i < mRunningThreadCount ; i++) {
109
- mThreads [i]->setAddonsAndTools (addonsAndTools);
110
- mThreads [i]->setSuppressions (mSuppressions );
111
- mThreads [i]->setClangIncludePaths (mClangIncludePaths );
112
- mThreads [i]->setSettings (settings, supprs);
118
+ setupCheckThread (*mThreads [i]);
113
119
mThreads [i]->start ();
114
120
}
115
121
@@ -123,14 +129,12 @@ void ThreadHandler::check(const Settings &settings, const std::shared_ptr<Suppre
123
129
124
130
bool ThreadHandler::isChecking () const
125
131
{
126
- return mRunningThreadCount > 0 ;
132
+ return mRunningThreadCount > 0 || mAnalyseWholeProgram ;
127
133
}
128
134
129
- void ThreadHandler::setThreadCount (const int count)
135
+ void ThreadHandler::createThreads (const int count)
130
136
{
131
- if (mRunningThreadCount > 0 ||
132
- count == mThreads .size () ||
133
- count <= 0 ) {
137
+ if (mRunningThreadCount > 0 || count <= 0 ) {
134
138
return ;
135
139
}
136
140
@@ -140,9 +144,9 @@ void ThreadHandler::setThreadCount(const int count)
140
144
for (int i = mThreads .size (); i < count; i++) {
141
145
mThreads << new CheckThread (mResults );
142
146
connect (mThreads .last (), &CheckThread::done,
143
- this , &ThreadHandler::threadDone);
147
+ this , &ThreadHandler::threadDone, Qt::QueuedConnection );
144
148
connect (mThreads .last (), &CheckThread::fileChecked,
145
- &mResults , &ThreadResult::fileChecked);
149
+ &mResults , &ThreadResult::fileChecked, Qt::QueuedConnection );
146
150
}
147
151
}
148
152
@@ -151,7 +155,7 @@ void ThreadHandler::removeThreads()
151
155
{
152
156
for (CheckThread* thread : mThreads ) {
153
157
if (thread->isRunning ()) {
154
- thread->terminate ();
158
+ thread->stop ();
155
159
thread->wait ();
156
160
}
157
161
disconnect (thread, &CheckThread::done,
@@ -162,19 +166,22 @@ void ThreadHandler::removeThreads()
162
166
}
163
167
164
168
mThreads .clear ();
165
- mAnalyseWholeProgram = false ;
166
169
}
167
170
168
171
void ThreadHandler::threadDone ()
169
172
{
170
- if (mRunningThreadCount == 1 && mAnalyseWholeProgram ) {
173
+ mRunningThreadCount --;
174
+
175
+ if (mRunningThreadCount == 0 && mAnalyseWholeProgram ) {
176
+ createThreads (1 );
177
+ mRunningThreadCount = 1 ;
178
+ setupCheckThread (*mThreads [0 ]);
171
179
mThreads [0 ]->analyseWholeProgram (mLastFiles , mCtuInfo );
172
180
mAnalyseWholeProgram = false ;
173
181
mCtuInfo .clear ();
174
182
return ;
175
183
}
176
184
177
- mRunningThreadCount --;
178
185
if (mRunningThreadCount == 0 ) {
179
186
emit done ();
180
187
@@ -185,6 +192,9 @@ void ThreadHandler::threadDone()
185
192
mLastCheckTime = mCheckStartTime ;
186
193
mCheckStartTime = QDateTime ();
187
194
}
195
+
196
+ mCheckAddonsAndTools .clear ();
197
+ mCheckSuppressions .reset ();
188
198
}
189
199
}
190
200
@@ -215,7 +225,7 @@ void ThreadHandler::initialize(const ResultsView *view)
215
225
216
226
void ThreadHandler::loadSettings (const QSettings &settings)
217
227
{
218
- setThreadCount (settings.value (SETTINGS_CHECK_THREADS, 1 ).toInt ());
228
+ createThreads (settings.value (SETTINGS_CHECK_THREADS, 1 ).toInt ());
219
229
}
220
230
221
231
void ThreadHandler::saveSettings (QSettings &settings) const
0 commit comments