From cc4a542e9dbc5223ba9e196e4ff7b21c28f4eda6 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 27 Jul 2008 16:13:57 +0000 Subject: [PATCH] BUGFIX: Limit the number of concurrent download threads to save memory --- Changelog | 1 + src/downloadThread.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index cae323300..6953c0615 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,7 @@ - FEATURE: The number of DHT nodes is displayed - FEATURE: RSS can now be disabled from program preferences - BUGFIX: Disable ETA calculation when ETA column is hidden + - BUGFIX: Limit the number of concurrent download threads to save memory - COSMETIC: Transfer speed, ratio and DHT nodes are displayed in status bar - COSMETIC: RSS Tab is now hidden as a default diff --git a/src/downloadThread.cpp b/src/downloadThread.cpp index 37f095f31..9f4d47976 100644 --- a/src/downloadThread.cpp +++ b/src/downloadThread.cpp @@ -24,6 +24,8 @@ #include #include +#define MAX_THREADS 3 + // http://curl.rtin.bz/libcurl/c/libcurl-errors.html QString subDownloadThread::errorCodeToString(CURLcode status) { switch(status){ @@ -165,7 +167,7 @@ void downloadThread::run(){ if(abort) return; mutex.lock(); - if(url_list.size() != 0){ + if(url_list.size() != 0 && subThreads.size() < MAX_THREADS){ QString url = url_list.takeFirst(); mutex.unlock(); subDownloadThread *st = new subDownloadThread(0, url); @@ -190,6 +192,9 @@ void downloadThread::propagateDownloadedFile(subDownloadThread* st, QString url, index = downloading_list.indexOf(url); Q_ASSERT(index != -1); downloading_list.removeAt(index); + if(url_list.size() != 0) { + condition.wakeOne(); + } mutex.unlock(); } @@ -203,5 +208,8 @@ void downloadThread::propagateDownloadFailure(subDownloadThread* st, QString url index = downloading_list.indexOf(url); Q_ASSERT(index != -1); downloading_list.removeAt(index); + if(url_list.size() != 0) { + condition.wakeOne(); + } mutex.unlock(); }