mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-12 09:29:41 +00:00
added workers mutex
This commit is contained in:
parent
3cbbb62562
commit
a886a17159
Heart/AbstractSpace
@ -136,10 +136,14 @@ void AbstractNode::stop() {
|
||||
}
|
||||
_connectionsMutex.unlock();
|
||||
|
||||
_workersMutex.lock();
|
||||
for (auto it: qAsConst(_workers)) {
|
||||
if (!it->isFinished())
|
||||
if (!it->isFinished()) {
|
||||
it->cancel();
|
||||
it->waitForFinished();
|
||||
}
|
||||
}
|
||||
_workersMutex.unlock();
|
||||
|
||||
deinitThreadPool();
|
||||
}
|
||||
@ -1015,7 +1019,10 @@ void AbstractNode::handleWorkerStoped() {
|
||||
|
||||
if (senderObject) {
|
||||
|
||||
_workersMutex.lock();
|
||||
_workers.remove(senderObject);
|
||||
_workersMutex.unlock();
|
||||
|
||||
delete senderObject;
|
||||
}
|
||||
}
|
||||
@ -1041,7 +1048,11 @@ void AbstractNode::handleBeginWork(QSharedPointer<QH::AbstractTask> work) {
|
||||
if (_threadPool) {
|
||||
auto worker = new QFutureWatcher <bool>();
|
||||
worker->setFuture(QtConcurrent::run(_threadPool, executeObject));
|
||||
|
||||
_workersMutex.lock();
|
||||
_workers.insert(worker);
|
||||
_workersMutex.unlock();
|
||||
|
||||
|
||||
connect(worker, &QFutureWatcher<bool>::finished,
|
||||
this, &AbstractNode::handleWorkerStoped);
|
||||
@ -1153,7 +1164,10 @@ void AbstractNode::newWork(const Package &pkg, AbstractNodeInfo *sender,
|
||||
if (_threadPool) {
|
||||
auto worker = new QFutureWatcher <bool>();
|
||||
worker->setFuture(QtConcurrent::run(_threadPool, executeObject));
|
||||
|
||||
_workersMutex.lock();
|
||||
_workers.insert(worker);
|
||||
_workersMutex.unlock();
|
||||
|
||||
connect(worker, &QFutureWatcher<bool>::finished,
|
||||
this, &AbstractNode::handleWorkerStoped);
|
||||
|
@ -717,6 +717,7 @@ private:
|
||||
mutable QMutex _connectionsMutex;
|
||||
mutable QMutex _confirmNodeMutex;
|
||||
mutable QMutex _threadPoolMutex;
|
||||
mutable QMutex _workersMutex;
|
||||
|
||||
QThreadPool *_threadPool = nullptr;
|
||||
QHash<unsigned short, std::function<PKG::AbstractData*()>> _registeredTypes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user