summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-02 17:07:20 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-02 17:07:20 +0300
commit79d27e4b7b4a86d8ca33456871de05f86d4d14c8 (patch)
tree076fb7e15c6fd8623a09a8e3ffdccb5bb897b831
parent436443304ddd09d98b30602dbbb670cc856e239e (diff)
downloadplus-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.gz
plus-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.bz2
plus-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.xz
plus-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.zip
Add temination flag for background download threads.
This probably will fix random crash in tests after start and exit.
-rw-r--r--src/client.cpp2
-rw-r--r--src/net/download.cpp24
2 files changed, 17 insertions, 9 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 307418964..21ea23ce1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -208,6 +208,7 @@ time_t start_time;
unsigned int mLastHost = 0;
unsigned long mSearchHash = 0;
int textures_count = 0;
+volatile bool isTerminate = false;
namespace
{
@@ -619,6 +620,7 @@ void Client::gameClear()
{
if (logger)
logger->log1("Quitting1");
+ isTerminate = true;
config.removeListeners(this);
delete2(assertListener);
diff --git a/src/net/download.cpp b/src/net/download.cpp
index feb92265c..6a1f4cc83 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -37,6 +37,8 @@
const char *DOWNLOAD_ERROR_MESSAGE_THREAD
= "Could not create download thread!";
+extern volatile bool isTerminate;
+
enum
{
OPTIONS_NONE = 0,
@@ -270,11 +272,14 @@ int Download::downloadThread(void *ptr)
d->mUrlQueue.pop();
logger->log_r("selected url: %s", d->mUrl.c_str());
- while (attempts < 3 && !complete && !d->mOptions.cancel)
+ while (attempts < 3 &&
+ !complete &&
+ !d->mOptions.cancel &&
+ isTerminate == false)
{
d->mUpdateFunction(d->mPtr, DownloadStatus::Starting, 0, 0);
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// need terminate thread?
d->mThread = nullptr;
@@ -282,7 +287,7 @@ int Download::downloadThread(void *ptr)
}
d->mCurl = curl_easy_init();
- if (d->mCurl && !d->mOptions.cancel)
+ if (d->mCurl && !d->mOptions.cancel && isTerminate == false)
{
FILE *file = nullptr;
@@ -337,8 +342,9 @@ int Download::downloadThread(void *ptr)
secureCurl(d->mCurl);
}
- if ((res = curl_easy_perform(d->mCurl)) != 0
- && !d->mOptions.cancel)
+ if ((res = curl_easy_perform(d->mCurl)) != 0 &&
+ !d->mOptions.cancel &&
+ isTerminate == false)
{
PRAGMA45(GCC diagnostic push)
PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
@@ -364,7 +370,7 @@ int Download::downloadThread(void *ptr)
continue;
}
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
break;
// d->mUpdateFunction(d->mPtr, DownloadStatus::Error, 0, 0);
@@ -429,7 +435,7 @@ int Download::downloadThread(void *ptr)
// Any existing file with this name is deleted first,
// otherwise the rename will fail on Windows.
- if (!d->mOptions.cancel)
+ if (!d->mOptions.cancel && isTerminate == false)
{
if (d->mIsXml)
{
@@ -469,7 +475,7 @@ int Download::downloadThread(void *ptr)
d->mCurl = nullptr;
}
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// need ternibate thread?
d->mThread = nullptr;
@@ -484,7 +490,7 @@ int Download::downloadThread(void *ptr)
d->mThread = nullptr;
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// Nothing to do...
}