From f6c3b44cfba97a89600f62e80660edc4df084d4c Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Fri, 10 Jun 2016 12:10:14 -0400 Subject: [PATCH] Fix QTimer not being stopped in right thread --- apps/opencs/model/doc/documentmanager.cpp | 1 + apps/opencs/model/doc/loader.cpp | 18 ++++++++++++++---- apps/opencs/model/doc/loader.hpp | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/doc/documentmanager.cpp b/apps/opencs/model/doc/documentmanager.cpp index cbb255ebb..87fb960c1 100644 --- a/apps/opencs/model/doc/documentmanager.cpp +++ b/apps/opencs/model/doc/documentmanager.cpp @@ -41,6 +41,7 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con CSMDoc::DocumentManager::~DocumentManager() { mLoaderThread.quit(); + mLoader.stop(); mLoader.hasThingsToDo().wakeAll(); mLoaderThread.wait(); diff --git a/apps/opencs/model/doc/loader.cpp b/apps/opencs/model/doc/loader.cpp index 166e6f3db..51b1b5884 100644 --- a/apps/opencs/model/doc/loader.cpp +++ b/apps/opencs/model/doc/loader.cpp @@ -1,6 +1,6 @@ #include "loader.hpp" -#include +#include #include "../tools/reportmodel.hpp" @@ -11,11 +11,12 @@ CSMDoc::Loader::Stage::Stage() : mFile (0), mRecordsLoaded (0), mRecordsLeft (fa CSMDoc::Loader::Loader() + : mShouldStop(false) { - QTimer *timer = new QTimer (this); + mTimer = new QTimer (this); - connect (timer, SIGNAL (timeout()), this, SLOT (load())); - timer->start(); + connect (mTimer, SIGNAL (timeout()), this, SLOT (load())); + mTimer->start(); } QWaitCondition& CSMDoc::Loader::hasThingsToDo() @@ -23,6 +24,11 @@ QWaitCondition& CSMDoc::Loader::hasThingsToDo() return mThingsToDo; } +void CSMDoc::Loader::stop() +{ + mShouldStop = true; +} + void CSMDoc::Loader::load() { if (mDocuments.empty()) @@ -30,6 +36,10 @@ void CSMDoc::Loader::load() mMutex.lock(); mThingsToDo.wait (&mMutex); mMutex.unlock(); + + if (mShouldStop) + mTimer->stop(); + return; } diff --git a/apps/opencs/model/doc/loader.hpp b/apps/opencs/model/doc/loader.hpp index d1ee38f9f..ce5bc5848 100644 --- a/apps/opencs/model/doc/loader.hpp +++ b/apps/opencs/model/doc/loader.hpp @@ -5,6 +5,7 @@ #include #include +#include #include namespace CSMDoc @@ -28,12 +29,17 @@ namespace CSMDoc QWaitCondition mThingsToDo; std::vector > mDocuments; + QTimer* mTimer; + bool mShouldStop; + public: Loader(); QWaitCondition& hasThingsToDo(); + void stop(); + private slots: void load();