aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazanski <q3k@q3k.org>2018-08-01 03:26:27 +0100
committerSergiusz Bazanski <q3k@q3k.org>2018-08-01 03:26:27 +0100
commitf9d30bcdea72e4860361d8ab350282703dc3bfcf (patch)
treeb15967aea47806335a5811dfc934260c39367319
parent9fb9eab6c9699df5cd86ca03563e0fa871defb83 (diff)
downloadnextpnr-f9d30bcdea72e4860361d8ab350282703dc3bfcf.tar.gz
nextpnr-f9d30bcdea72e4860361d8ab350282703dc3bfcf.tar.bz2
nextpnr-f9d30bcdea72e4860361d8ab350282703dc3bfcf.zip
gui: lock arch when accessing/building treemodel
-rw-r--r--gui/designwidget.cc15
-rw-r--r--gui/treemodel.cc8
-rw-r--r--gui/treemodel.h3
3 files changed, 23 insertions, 3 deletions
diff --git a/gui/designwidget.cc b/gui/designwidget.cc
index c75991eb..34e358ae 100644
--- a/gui/designwidget.cc
+++ b/gui/designwidget.cc
@@ -215,7 +215,11 @@ void DesignWidget::newContext(Context *ctx)
highlightSelected.clear();
this->ctx = ctx;
- treeModel->loadContext(ctx);
+ {
+ std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
+ std::lock_guard<std::mutex> lock(ctx->mutex);
+ treeModel->loadContext(ctx);
+ }
updateTree();
}
@@ -235,7 +239,11 @@ void DesignWidget::updateTree()
}
}
- treeModel->updateCellsNets(ctx);
+ {
+ std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
+ std::lock_guard<std::mutex> lock(ctx->mutex);
+ treeModel->updateCellsNets(ctx);
+ }
}
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
{
@@ -735,6 +743,9 @@ void DesignWidget::onSearchInserted()
if (currentIndex >= currentSearchIndexes.size())
currentIndex = 0;
} else {
+ std::lock_guard<std::mutex> lock_ui(ctx->ui_mutex);
+ std::lock_guard<std::mutex> lock(ctx->mutex);
+
currentSearch = searchEdit->text();
currentSearchIndexes = treeModel->search(searchEdit->text());
currentIndex = 0;
diff --git a/gui/treemodel.cc b/gui/treemodel.cc
index 4fc3d4f5..bf7d81a3 100644
--- a/gui/treemodel.cc
+++ b/gui/treemodel.cc
@@ -146,6 +146,7 @@ void Model::loadContext(Context *ctx)
{
if (!ctx)
return;
+ ctx_ = ctx;
beginResetModel();
@@ -273,6 +274,12 @@ Qt::ItemFlags Model::flags(const QModelIndex &index) const
void Model::fetchMore(const QModelIndex &parent)
{
+ if (ctx_ == nullptr)
+ return;
+
+ std::lock_guard<std::mutex> lock_ui(ctx_->ui_mutex);
+ std::lock_guard<std::mutex> lock(ctx_->mutex);
+
nodeFromIndex(parent)->fetchMore();
}
@@ -284,7 +291,6 @@ bool Model::canFetchMore(const QModelIndex &parent) const
QList<QModelIndex> Model::search(QString text)
{
const int limit = 500;
-
QList<Item*> list;
cell_root_->search(list, text, limit);
net_root_->search(list, text, limit);
diff --git a/gui/treemodel.h b/gui/treemodel.h
index 15370658..1d25dde4 100644
--- a/gui/treemodel.h
+++ b/gui/treemodel.h
@@ -355,6 +355,9 @@ class ElementXYRoot : public Item
class Model : public QAbstractItemModel
{
+ private:
+ Context *ctx_ = nullptr;
+
public:
using BelXYRoot = ElementXYRoot<BelId>;
using WireXYRoot = ElementXYRoot<WireId>;