mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
- Optimized downloadThread mmemory usage
This commit is contained in:
parent
cc4a542e9d
commit
6a95f9170c
@ -152,9 +152,7 @@ downloadThread::~downloadThread(){
|
|||||||
|
|
||||||
void downloadThread::downloadUrl(QString url){
|
void downloadThread::downloadUrl(QString url){
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
if(downloading_list.contains(url)) return;
|
urls_queue.enqueue(url);
|
||||||
url_list << url;
|
|
||||||
downloading_list << url;
|
|
||||||
if(!isRunning()){
|
if(!isRunning()){
|
||||||
start();
|
start();
|
||||||
}else{
|
}else{
|
||||||
@ -167,8 +165,8 @@ void downloadThread::run(){
|
|||||||
if(abort)
|
if(abort)
|
||||||
return;
|
return;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if(url_list.size() != 0 && subThreads.size() < MAX_THREADS){
|
if(!urls_queue.empty() && subThreads.size() < MAX_THREADS){
|
||||||
QString url = url_list.takeFirst();
|
QString url = urls_queue.dequeue();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
subDownloadThread *st = new subDownloadThread(0, url);
|
subDownloadThread *st = new subDownloadThread(0, url);
|
||||||
subThreads << st;
|
subThreads << st;
|
||||||
@ -189,10 +187,7 @@ void downloadThread::propagateDownloadedFile(subDownloadThread* st, QString url,
|
|||||||
delete st;
|
delete st;
|
||||||
emit downloadFinished(url, path);
|
emit downloadFinished(url, path);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
index = downloading_list.indexOf(url);
|
if(!urls_queue.empty()) {
|
||||||
Q_ASSERT(index != -1);
|
|
||||||
downloading_list.removeAt(index);
|
|
||||||
if(url_list.size() != 0) {
|
|
||||||
condition.wakeOne();
|
condition.wakeOne();
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
@ -205,10 +200,7 @@ void downloadThread::propagateDownloadFailure(subDownloadThread* st, QString url
|
|||||||
delete st;
|
delete st;
|
||||||
emit downloadFailure(url, reason);
|
emit downloadFailure(url, reason);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
index = downloading_list.indexOf(url);
|
if(!urls_queue.empty()) {
|
||||||
Q_ASSERT(index != -1);
|
|
||||||
downloading_list.removeAt(index);
|
|
||||||
if(url_list.size() != 0) {
|
|
||||||
condition.wakeOne();
|
condition.wakeOne();
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include <QQueue>
|
||||||
|
|
||||||
class subDownloadThread : public QThread {
|
class subDownloadThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -55,8 +56,7 @@ class downloadThread : public QThread {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList url_list;
|
QQueue<QString> urls_queue;
|
||||||
QStringList downloading_list;
|
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
QWaitCondition condition;
|
QWaitCondition condition;
|
||||||
bool abort;
|
bool abort;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user