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 // Create threads
unsigned int threads = config.iThreads; unsigned int threads = std::min(config.iThreads, static_cast<unsigned int>(gameItemQueue.size()));
if (gameItemQueue.size() < config.iThreads)
{
threads = gameItemQueue.size();
}
std::vector<std::thread> vThreads; std::vector<std::thread> vThreads;
for (unsigned int i = 0; i < threads; ++i) 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 // Create download threads
std::vector<std::thread> vThreads; std::vector<std::thread> vThreads;
for (unsigned int i = 0; i < config.iThreads; ++i) for (unsigned int i = 0; i < iThreads; ++i)
{ {
DownloadInfo dlInfo; DownloadInfo dlInfo;
dlInfo.setStatus(DLSTATUS_NOTSTARTED); dlInfo.setStatus(DLSTATUS_NOTSTARTED);
@ -1024,6 +1025,7 @@ void Downloader::download()
vThreads.clear(); vThreads.clear();
vDownloadInfo.clear(); vDownloadInfo.clear();
}
// Create xml data for all files in the queue // Create xml data for all files in the queue
if (!createXMLQueue.empty()) if (!createXMLQueue.empty())