Guard the flag used for deferred session configure.

This commit is contained in:
sledgehammer999 2016-10-30 00:43:53 +03:00
parent 1757973f88
commit 5cbc7b16c0
2 changed files with 12 additions and 4 deletions

View file

@ -911,6 +911,9 @@ void Session::adjustLimits()
void Session::configure() void Session::configure()
{ {
qDebug("Configuring session"); qDebug("Configuring session");
if (!m_deferredConfigureScheduled) return; // Obtaining the lock is expensive, let's check early
QWriteLocker locker(&m_lock);
if (!m_deferredConfigureScheduled) return; // something might have changed while we were getting the lock
#if LIBTORRENT_VERSION_NUM < 10100 #if LIBTORRENT_VERSION_NUM < 10100
libt::session_settings sessionSettings = m_nativeSession->settings(); libt::session_settings sessionSettings = m_nativeSession->settings();
configure(sessionSettings); configure(sessionSettings);
@ -2957,10 +2960,12 @@ void Session::initResumeFolder()
void Session::configureDeferred() void Session::configureDeferred()
{ {
if (!m_deferredConfigureScheduled) { if (m_deferredConfigureScheduled) return; // Obtaining the lock is expensive, let's check early
QMetaObject::invokeMethod(this, "configure", Qt::QueuedConnection); QWriteLocker locker(&m_lock);
m_deferredConfigureScheduled = true; if (m_deferredConfigureScheduled) return; // something might have changed while we were getting the lock
}
QMetaObject::invokeMethod(this, "configure", Qt::QueuedConnection);
m_deferredConfigureScheduled = true;
} }
// Enable IP Filtering // Enable IP Filtering

View file

@ -41,6 +41,7 @@
#endif #endif
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#include <QPointer> #include <QPointer>
#include <QReadWriteLock>
#include <QStringList> #include <QStringList>
#include <QVector> #include <QVector>
#include <QWaitCondition> #include <QWaitCondition>
@ -604,6 +605,8 @@ namespace BitTorrent
QNetworkConfigurationManager m_networkManager; QNetworkConfigurationManager m_networkManager;
mutable QReadWriteLock m_lock;
static Session *m_instance; static Session *m_instance;
}; };
} }