Make AnalThread interruptable (Fix #264)

This commit is contained in:
Florian Märkl 2018-03-09 13:57:57 +01:00
parent d3e48cdae1
commit 051b95c69d
4 changed files with 39 additions and 3 deletions

View File

@ -9,7 +9,8 @@ AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent),
level(2),
main(nullptr),
core(CutterCore::getInstance())
core(CutterCore::getInstance()),
interrupted(false)
{
}
@ -31,6 +32,17 @@ void AnalThread::start(MainWindow *main, int level, QList<QString> advanced)
QThread::start();
}
void AnalThread::interruptAndWait()
{
interrupted = true;
while(isRunning())
{
r_cons_singleton()->breaked = true;
r_sys_usleep(10000);
}
}
// run() will be called when a thread starts
void AnalThread::run()
{
@ -40,6 +52,8 @@ void AnalThread::run()
ut64 loadaddr = 0LL;
ut64 mapaddr = 0LL;
interrupted = false;
//
// Advanced Options
//
@ -106,7 +120,7 @@ void AnalThread::run()
}
core->setBBSize(optionsDialog->getSelectedBBSize());
// use prj.simple as default as long as regular projects are broken
core->setConfig("prj.simple", true);

View File

@ -15,6 +15,9 @@ public:
~AnalThread();
void start(MainWindow *main, int level, QList<QString> advanced);
void interruptAndWait();
bool isInterrupted() { return interrupted; }
protected:
void run();
@ -29,6 +32,8 @@ private:
QList<QString> advanced;
MainWindow *main;
CutterCore *core;
bool interrupted;
};
#endif // ANALTHREAD_H

View File

@ -262,6 +262,12 @@ void OptionsDialog::on_okButton_clicked()
void OptionsDialog::anal_finished()
{
if (analThread.isInterrupted())
{
done(0);
return;
}
ui->statusLabel->setText(tr("Loading interface"));
main->addOutput(tr(" > Analysis finished"));
@ -269,6 +275,15 @@ void OptionsDialog::anal_finished()
done(0);
}
void OptionsDialog::closeEvent(QCloseEvent *event)
{
if (analThread.isRunning())
{
analThread.interruptAndWait();
}
event->accept();
}
QString OptionsDialog::analysisDescription(int level)
{
//TODO: replace this with meaningful descriptions
@ -362,7 +377,6 @@ void OptionsDialog::on_pdbSelectButton_clicked()
void OptionsDialog::reject()
{
delete main;
done(0);
NewFileDialog *n = new NewFileDialog(nullptr);
n->show();

View File

@ -40,6 +40,9 @@ private slots:
void anal_finished();
protected:
void closeEvent(QCloseEvent *event) override;
private:
AnalThread analThread;
MainWindow *main;