Commit 0dd18040 authored by Valentin Platzgummer's avatar Valentin Platzgummer

nemo.cpp: deadlock when calling stop during synchronization removed

parent faf642f3
#include "MeasurementComplexItem.h" #include "MeasurementComplexItem.h"
#include "AreaData.h"
#include "CircularGenerator.h" #include "CircularGenerator.h"
#include "LinearGenerator.h" #include "LinearGenerator.h"
#include "NemoInterface.h" #include "NemoInterface.h"
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include "QGCQGeoCoordinate.h" #include "QGCQGeoCoordinate.h"
#include "SettingsFact.h" #include "SettingsFact.h"
#include "AreaData.h"
#include "geometry/ProgressArray.h" #include "geometry/ProgressArray.h"
class AreaData;
class RoutingThread; class RoutingThread;
class RoutingResult; class RoutingResult;
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include "TilePtrArray.h" #include "TilePtrArray.h"
#include "geometry/ProgressArray.h" #include "geometry/ProgressArray.h"
// Singelton class used to interface measurement devices implementing the nemo
// interface.
class NemoInterface : public QObject { class NemoInterface : public QObject {
Q_OBJECT Q_OBJECT
class Impl; class Impl;
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "QmlObjectListHelper.h" #include "QmlObjectListHelper.h"
#include "MeasurementComplexItem/nemo_interface/MeasurementTile.h"
#ifndef MAX_TILES #ifndef MAX_TILES
#define MAX_TILES 1000 #define MAX_TILES 1000
#endif #endif
...@@ -602,27 +604,6 @@ void MeasurementArea::setState(MeasurementArea::STATE s) { ...@@ -602,27 +604,6 @@ void MeasurementArea::setState(MeasurementArea::STATE s) {
} }
} }
void MeasurementArea::updateIds(const QList<TileDiff> &array) {
for (const auto &diff : array) {
auto it = _indexMap.find(diff.oldTile.id());
if (it != _indexMap.end()) {
int tileIndex = it->second;
auto *tile = _tiles->value<MeasurementTile *>(tileIndex);
if (diff.oldTile.coordinateList() == tile->coordinateList()) {
// Change id and update _tileMap.
const auto newId = diff.newTile.id();
tile->setId(newId);
_indexMap.erase(it);
auto ret = _indexMap.insert(std::make_pair(newId, tileIndex));
Q_ASSERT(ret.second == true /*insert success?*/);
Q_UNUSED(ret);
}
}
}
}
bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth, bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth,
Area minTileArea, std::vector<FPolygon> &tiles, Area minTileArea, std::vector<FPolygon> &tiles,
BoundingBox &bbox) { BoundingBox &bbox) {
......
...@@ -6,10 +6,8 @@ ...@@ -6,10 +6,8 @@
#include <QTimer> #include <QTimer>
#include "GeoArea.h" #include "GeoArea.h"
#include "MeasurementComplexItem/nemo_interface/MeasurementTile.h"
#include "ProgressArray.h"
#include "TileDiff.h"
#include "ProgressArray.h"
#include "SettingsFact.h" #include "SettingsFact.h"
class MeasurementArea : public GeoArea { class MeasurementArea : public GeoArea {
...@@ -61,7 +59,6 @@ signals: ...@@ -61,7 +59,6 @@ signals:
void progressChanged(); void progressChanged();
public slots: public slots:
void updateIds(const QList<TileDiff> &array);
void updateProgress(const ProgressArray &array); void updateProgress(const ProgressArray &array);
Q_INVOKABLE void randomProgress(); Q_INVOKABLE void randomProgress();
Q_INVOKABLE void resetProgress(); Q_INVOKABLE void resetProgress();
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define PROGRESSARRAY_H #define PROGRESSARRAY_H
#include <QVector> #include <QVector>
#include <tuple>
#include "comm/ros_bridge/include/messages/nemo_msgs/labeled_progress.h" #include "comm/ros_bridge/include/messages/nemo_msgs/labeled_progress.h"
......
...@@ -52,11 +52,7 @@ void TaskDispatcher::start() { ...@@ -52,11 +52,7 @@ void TaskDispatcher::start() {
ULock lk1(this->_mutex); ULock lk1(this->_mutex);
if (!_running) { if (!_running) {
this->_running = true; this->_running = true;
auto p = std::make_shared<std::promise<void>>(); QtConcurrent::run([this]() mutable { return this->run(); });
_threadFuture = p->get_future();
QtConcurrent::run([this, p = std::move(p)]() mutable {
return this->run(std::move(*p));
});
lk1.unlock(); lk1.unlock();
} }
} }
...@@ -65,7 +61,6 @@ void TaskDispatcher::stop() { ...@@ -65,7 +61,6 @@ void TaskDispatcher::stop() {
ULock lk1(this->_mutex); ULock lk1(this->_mutex);
if (_running) { if (_running) {
this->_running = false; this->_running = false;
_threadFuture.wait();
lk1.unlock(); lk1.unlock();
} }
} }
...@@ -92,7 +87,7 @@ std::size_t TaskDispatcher::pendingTasks() { ...@@ -92,7 +87,7 @@ std::size_t TaskDispatcher::pendingTasks() {
bool TaskDispatcher::idle() { return this->pendingTasks() == 0; } bool TaskDispatcher::idle() { return this->pendingTasks() == 0; }
void TaskDispatcher::run(std::promise<void> p) { void TaskDispatcher::run() {
while (true) { while (true) {
ULock lk1(this->_mutex); ULock lk1(this->_mutex);
...@@ -116,7 +111,6 @@ void TaskDispatcher::run(std::promise<void> p) { ...@@ -116,7 +111,6 @@ void TaskDispatcher::run(std::promise<void> p) {
break; break;
} }
} }
p.set_value();
} }
} // namespace nemo_interface } // namespace nemo_interface
...@@ -56,12 +56,11 @@ public: ...@@ -56,12 +56,11 @@ public:
bool idle(); bool idle();
protected: protected:
void run(std::promise<void> p); void run();
private: private:
std::deque<std::unique_ptr<Task>> _taskQueue; std::deque<std::unique_ptr<Task>> _taskQueue;
std::deque<std::promise<QVariant>> _promiseQueue; std::deque<std::promise<QVariant>> _promiseQueue;
std::future<void> _threadFuture;
bool _running; bool _running;
std::mutex _mutex; std::mutex _mutex;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment