mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Make AnalThread interruptable (Fix #264)
This commit is contained in:
parent
d3e48cdae1
commit
051b95c69d
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -40,6 +40,9 @@ private slots:
|
||||
|
||||
void anal_finished();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
AnalThread analThread;
|
||||
MainWindow *main;
|
||||
|
Loading…
Reference in New Issue
Block a user