From 5cbc7b16c04331599f382fa71bdc73f4aed476c7 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 30 Oct 2016 00:43:53 +0300 Subject: [PATCH] Guard the flag used for deferred session configure. --- src/base/bittorrent/session.cpp | 13 +++++++++---- src/base/bittorrent/session.h | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 40b8cd28d..758ef3663 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -911,6 +911,9 @@ void Session::adjustLimits() void Session::configure() { 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 libt::session_settings sessionSettings = m_nativeSession->settings(); configure(sessionSettings); @@ -2957,10 +2960,12 @@ void Session::initResumeFolder() void Session::configureDeferred() { - if (!m_deferredConfigureScheduled) { - QMetaObject::invokeMethod(this, "configure", Qt::QueuedConnection); - m_deferredConfigureScheduled = true; - } + 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 + + QMetaObject::invokeMethod(this, "configure", Qt::QueuedConnection); + m_deferredConfigureScheduled = true; } // Enable IP Filtering diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 847447edf..82fd6f00c 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -41,6 +41,7 @@ #endif #include #include +#include #include #include #include @@ -604,6 +605,8 @@ namespace BitTorrent QNetworkConfigurationManager m_networkManager; + mutable QReadWriteLock m_lock; + static Session *m_instance; }; }