mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Limit download thread count to number of items in download queue
This commit is contained in:
parent
dea82b7991
commit
9f214d9652
@ -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,25 +1002,31 @@ void Downloader::download()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create download threads
|
if (!dlQueue.empty())
|
||||||
std::vector<std::thread> vThreads;
|
|
||||||
for (unsigned int i = 0; i < config.iThreads; ++i)
|
|
||||||
{
|
{
|
||||||
DownloadInfo dlInfo;
|
// Limit thread count to number of items in download queue
|
||||||
dlInfo.setStatus(DLSTATUS_NOTSTARTED);
|
unsigned int iThreads = std::min(config.iThreads, static_cast<unsigned int>(dlQueue.size()));
|
||||||
vDownloadInfo.push_back(dlInfo);
|
|
||||||
vThreads.push_back(std::thread(Downloader::processDownloadQueue, this->config, i));
|
// Create download threads
|
||||||
|
std::vector<std::thread> vThreads;
|
||||||
|
for (unsigned int i = 0; i < iThreads; ++i)
|
||||||
|
{
|
||||||
|
DownloadInfo dlInfo;
|
||||||
|
dlInfo.setStatus(DLSTATUS_NOTSTARTED);
|
||||||
|
vDownloadInfo.push_back(dlInfo);
|
||||||
|
vThreads.push_back(std::thread(Downloader::processDownloadQueue, this->config, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
this->printProgress();
|
||||||
|
|
||||||
|
// Join threads
|
||||||
|
for (unsigned int i = 0; i < vThreads.size(); ++i)
|
||||||
|
vThreads[i].join();
|
||||||
|
|
||||||
|
vThreads.clear();
|
||||||
|
vDownloadInfo.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->printProgress();
|
|
||||||
|
|
||||||
// Join threads
|
|
||||||
for (unsigned int i = 0; i < vThreads.size(); ++i)
|
|
||||||
vThreads[i].join();
|
|
||||||
|
|
||||||
vThreads.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())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user