Limit download thread count to number of items in download queue

This commit is contained in:
Sude 2016-12-18 18:25:24 +02:00
parent dea82b7991
commit 9f214d9652

View File

@ -334,11 +334,7 @@ int Downloader::getGameDetails()
}
// Create threads
unsigned int threads = config.iThreads;
if (gameItemQueue.size() < config.iThreads)
{
threads = gameItemQueue.size();
}
unsigned int threads = std::min(config.iThreads, static_cast<unsigned int>(gameItemQueue.size()));
std::vector<std::thread> vThreads;
for (unsigned int i = 0; i < threads; ++i)
{
@ -1006,9 +1002,14 @@ void Downloader::download()
}
}
if (!dlQueue.empty())
{
// Limit thread count to number of items in download queue
unsigned int iThreads = std::min(config.iThreads, static_cast<unsigned int>(dlQueue.size()));
// Create download threads
std::vector<std::thread> vThreads;
for (unsigned int i = 0; i < config.iThreads; ++i)
for (unsigned int i = 0; i < iThreads; ++i)
{
DownloadInfo dlInfo;
dlInfo.setStatus(DLSTATUS_NOTSTARTED);
@ -1024,6 +1025,7 @@ void Downloader::download()
vThreads.clear();
vDownloadInfo.clear();
}
// Create xml data for all files in the queue
if (!createXMLQueue.empty())