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()
|
void CheckThread::run()
|
||||||
{
|
{
|
||||||
|
mState = Running;
|
||||||
QString file;
|
QString file;
|
||||||
file = mResult.GetNextFile();
|
file = mResult.GetNextFile();
|
||||||
|
|
||||||
while (!file.isEmpty())
|
while (!file.isEmpty() && mState == Running)
|
||||||
{
|
{
|
||||||
qDebug() << "Checking file" << file;
|
qDebug() << "Checking file" << file;
|
||||||
mCppcheck.addFile(file.toStdString());
|
mCppcheck.addFile(file.toStdString());
|
||||||
|
@ -51,11 +52,18 @@ void CheckThread::run()
|
||||||
mCppcheck.clearFiles();
|
mCppcheck.clearFiles();
|
||||||
emit FileChecked(file);
|
emit FileChecked(file);
|
||||||
|
|
||||||
file = mResult.GetNextFile();
|
if (mState == Running)
|
||||||
|
file = mResult.GetNextFile();
|
||||||
}
|
}
|
||||||
|
if (mState == Running)
|
||||||
|
mState = Ready;
|
||||||
|
else
|
||||||
|
mState = Stopped;
|
||||||
|
|
||||||
emit Done();
|
emit Done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckThread::stop()
|
||||||
|
{
|
||||||
|
mState = Stopping;
|
||||||
|
}
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
@ -60,6 +62,27 @@ signals:
|
||||||
|
|
||||||
void FileChecked(const QString &file);
|
void FileChecked(const QString &file);
|
||||||
protected:
|
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;
|
ThreadResult &mResult;
|
||||||
/**
|
/**
|
||||||
* @brief Cppcheck itself
|
* @brief Cppcheck itself
|
||||||
|
|
|
@ -105,8 +105,7 @@ MainWindow::MainWindow() :
|
||||||
|
|
||||||
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
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(&mActionSave, SIGNAL(triggered()), this, SLOT(Save()));
|
||||||
|
|
||||||
connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
|
connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
|
||||||
|
|
|
@ -124,7 +124,7 @@ void ThreadHandler::Stop()
|
||||||
{
|
{
|
||||||
for (int i = 0;i < mThreads.size();i++)
|
for (int i = 0;i < mThreads.size();i++)
|
||||||
{
|
{
|
||||||
mThreads[i]->terminate();
|
mThreads[i]->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue