aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index bfa3df4..d402d36 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -95,11 +95,12 @@ namespace dchat
return { (sf::Texture*)nullptr, ImageByUrlResult::Type::FAILED_DOWNLOAD };
}
- Cache::Cache()
+ Cache::Cache() :
+ alive(true)
{
downloadWaitThread = thread([this]
{
- while(true)
+ while(alive)
{
for(vector<ImageDownloadInfo>::iterator it = imageDownloadProcesses.begin(); it != imageDownloadProcesses.end();)
{
@@ -133,7 +134,7 @@ namespace dchat
++it;
}
- while(imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty())
+ while(alive && imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty())
this_thread::sleep_for(chrono::milliseconds(20));
if(!imageDownloadProcessesQueue.empty())
@@ -150,7 +151,12 @@ namespace dchat
this_thread::sleep_for(chrono::milliseconds(20));
}
});
- downloadWaitThread.detach();
+ }
+
+ Cache::~Cache()
+ {
+ alive = false;
+ downloadWaitThread.join();
}
const ImageByUrlResult Cache::getImageByUrl(const string &url, int downloadLimitBytes)