GUI: Implement stopping the compare.
Threads must be exited from check cleanly even though it takes small amount of time. Just terminating thread can have unpredictable side-effects (even weird crashes).
This commit is contained in:
parent
e791d1c960
commit
027c31f39c
|
@ -40,10 +40,11 @@ void CheckThread::Check(Settings settings)
|
|||
|
||||
void CheckThread::run()
|
||||
{
|
||||
mState = Running;
|
||||
QString file;
|
||||
file = mResult.GetNextFile();
|
||||
|
||||
while (!file.isEmpty())
|
||||
while (!file.isEmpty() && mState == Running)
|
||||
{
|
||||
qDebug() << "Checking file" << file;
|
||||
mCppcheck.addFile(file.toStdString());
|
||||
|
@ -51,11 +52,18 @@ void CheckThread::run()
|
|||
mCppcheck.clearFiles();
|
||||
emit FileChecked(file);
|
||||
|
||||
if (mState == Running)
|
||||
file = mResult.GetNextFile();
|
||||
}
|
||||
if (mState == Running)
|
||||
mState = Ready;
|
||||
else
|
||||
mState = Stopped;
|
||||
|
||||
emit Done();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CheckThread::stop()
|
||||
{
|
||||
mState = Stopping;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
*/
|
||||
void run();
|
||||
|
||||
void stop();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -60,6 +62,27 @@ signals:
|
|||
|
||||
void FileChecked(const QString &file);
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief States for the check thread.
|
||||
* Whole purpose of these states is to allow stopping of the checking. When
|
||||
* stopping we say for the thread (Stopping) that "stop when current check
|
||||
* has been completed. Thread must be stopped cleanly, just terminating thread
|
||||
* likely causes unpredictable side-effedts.
|
||||
*/
|
||||
enum State
|
||||
{
|
||||
Running, /**< The thread is checking. */
|
||||
Stopping, /**< The thread will stop after current work. */
|
||||
Stopped, /**< The thread has been stopped. */
|
||||
Ready, /**< The thread is ready. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Thread's current execution state.
|
||||
*/
|
||||
State mState;
|
||||
|
||||
ThreadResult &mResult;
|
||||
/**
|
||||
* @brief Cppcheck itself
|
||||
|
|
|
@ -105,8 +105,7 @@ MainWindow::MainWindow() :
|
|||
|
||||
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
||||
|
||||
//TODO: This crashed
|
||||
//connect(&mActionStop, SIGNAL(triggered()), &mThread, SLOT(Stop()));
|
||||
connect(&mActionStop, SIGNAL(triggered()), &mThread, SLOT(Stop()));
|
||||
connect(&mActionSave, SIGNAL(triggered()), this, SLOT(Save()));
|
||||
|
||||
connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
|
||||
|
|
|
@ -124,7 +124,7 @@ void ThreadHandler::Stop()
|
|||
{
|
||||
for (int i = 0;i < mThreads.size();i++)
|
||||
{
|
||||
mThreads[i]->terminate();
|
||||
mThreads[i]->stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue