diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-22 12:11:22 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-22 12:49:40 +0200 |
commit | 3cd12e3671e5ee108f039cb4350bf885164a8cf5 (patch) | |
tree | 14e34395eae07ebcd7bb864754484b17558ae2b7 /gui/ice40/worker.cc | |
parent | 71176ac5384c696dde1d5601ea1beb5c46f281c6 (diff) | |
download | nextpnr-3cd12e3671e5ee108f039cb4350bf885164a8cf5.tar.gz nextpnr-3cd12e3671e5ee108f039cb4350bf885164a8cf5.tar.bz2 nextpnr-3cd12e3671e5ee108f039cb4350bf885164a8cf5.zip |
Add ability to terminate running tasks
Diffstat (limited to 'gui/ice40/worker.cc')
-rw-r--r-- | gui/ice40/worker.cc | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 5702137b..a309f868 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,9 +10,19 @@ #include "route.h" #include "timing.h" -Worker::Worker(Context *_ctx) : ctx(_ctx) +struct WorkerInterruptionRequested { - log_write_function = [this](std::string text) { Q_EMIT log(text); }; +}; + +Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) +{ + log_write_function = [this, parent](std::string text) { + Q_EMIT log(text); + if (parent->shouldTerminate()) { + parent->clearTerminate(); + throw WorkerInterruptionRequested(); + } + }; } void Worker::parsejson(const std::string &filename) @@ -32,14 +42,16 @@ void Worker::parsejson(const std::string &filename) log_error("Placing design failed.\n"); if (!route_design(ctx)) log_error("Routing design failed.\n"); - Q_EMIT log("done"); + Q_EMIT log("DONE\n"); } catch (log_execution_error_exception) { + } catch (WorkerInterruptionRequested) { + Q_EMIT log("CANCELED\n"); } } -TaskManager::TaskManager(Context *ctx) +TaskManager::TaskManager(Context *ctx) : toTerminate(false) { - Worker *worker = new Worker(ctx); + Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &TaskManager::parsejson, worker, &Worker::parsejson); @@ -53,4 +65,22 @@ TaskManager::~TaskManager() workerThread.wait(); } -void TaskManager::info(const std::string &result) { Q_EMIT log(result); }
\ No newline at end of file +void TaskManager::info(const std::string &result) { Q_EMIT log(result); } + +void TaskManager::terminate_thread() +{ + QMutexLocker locker(&mutex); + toTerminate = true; +} + +bool TaskManager::shouldTerminate() +{ + QMutexLocker locker(&mutex); + return toTerminate; +} + +void TaskManager::clearTerminate() +{ + QMutexLocker locker(&mutex); + toTerminate = false; +}
\ No newline at end of file |