Skip to content

Commit a466513

Browse files
committed
https://github.com/mwcproject/mwc-qt-wallet/issues/319
1 parent ffeac84 commit a466513

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

wallet/mwc713.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,27 @@ void MWC713::processStop(bool exitNicely) {
327327
emit onMwcAddressWithIndex("",1);
328328

329329
if (mwc713process) {
330+
// Waitiong for task Q to be empty
331+
// Note, event processing can change a lot for us, so we shoudl watch for variables
330332
if (exitNicely) {
331333
qDebug() << "start exiting...";
332-
executeMwc713command("exit", "");
333334

334-
if (!util::processWaitForFinished( mwc713process, 5000, "mwc713")) {
335+
int taskTimeout = 0;
336+
if (eventCollector != nullptr)
337+
taskTimeout += eventCollector->cancelTasksInQueue();
338+
339+
if (taskTimeout <= 10000) {
340+
executeMwc713command("exit", "");
341+
}
342+
else {
343+
logger::logInfo("MWC713", QString("mwc713 terminating because running long task that required to stop ") + QString::number(taskTimeout) + "ms");
344+
taskTimeout = 0;
345+
mwc713process->terminate();
346+
}
347+
348+
if (!util::processWaitForFinished( mwc713process, 3000 + taskTimeout, "mwc713")) {
335349
mwc713process->terminate();
336-
util::processWaitForFinished( mwc713process, 5000, "mwc713");
350+
util::processWaitForFinished( mwc713process, 3000 + taskTimeout, "mwc713");
337351
}
338352
qDebug() << "mwc713 is exited";
339353
}

wallet/mwc713events.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ bool Mwc713EventManager::addFirstTask( Mwc713Task * task, int64_t timeout) {
158158
return true;
159159
}
160160

161+
// Running and waiting tasks number
162+
int Mwc713EventManager::cancelTasksInQueue() {
163+
QMutexLocker l( &taskQMutex );
164+
165+
if (taskQ.isEmpty()) {
166+
return 0;
167+
}
168+
169+
taskQ.resize(1);
170+
return taskQ[0].timeout;
171+
}
172+
161173

162174
// Process next task
163175
void Mwc713EventManager::processNextTask() {

wallet/mwc713events.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class Mwc713EventManager : public QObject
155155

156156
const QVector<WEvent> & getEvents() const {return events;}
157157

158+
// Cancelling all tasks except the current one. Return timeout valiue that needed to wait
159+
int cancelTasksInQueue();
160+
158161
// clean all tasks, events and all
159162
void clear();
160163
public slots:

0 commit comments

Comments
 (0)