From ed56520d2488082a83e9751fde7fc9651d838b2d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 20 Jan 2012 05:40:32 +0000 Subject: [PATCH] more asserts around state updates --- include/libtorrent/aux_/session_impl.hpp | 6 +++++- src/session_impl.cpp | 6 +++++- src/torrent.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index ded435aa1..cc90b47cf 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -503,7 +503,11 @@ namespace libtorrent } void add_to_update_queue(boost::weak_ptr t) - { m_state_updates.push_back(t); } + { + TORRENT_ASSERT(std::find_if(m_state_updates.begin(), m_state_updates.end() + , boost::bind(&boost::weak_ptr::lock, _1) == t.lock()) == m_state_updates.end()); + m_state_updates.push_back(t); + } // private: diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9bb4cda88..a4b448d06 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4548,6 +4548,10 @@ namespace aux { void session_impl::post_torrent_updates() { + INVARIANT_CHECK; + + TORRENT_ASSERT(is_network_thread()); + std::auto_ptr alert(new state_update_alert()); alert->status.reserve(m_state_updates.size()); @@ -4557,8 +4561,8 @@ namespace aux { boost::shared_ptr t = i->lock(); if (!t) continue; alert->status.push_back(torrent_status()); - t->clear_in_state_update(); t->status(&alert->status.back(), 0xffffffff); + t->clear_in_state_update(); } m_state_updates.clear(); diff --git a/src/torrent.cpp b/src/torrent.cpp index bbcd042b2..7e47a724f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -7999,7 +7999,13 @@ namespace libtorrent // we're either not subscribing to this torrent, or // it has already been updated this round, no need to // add it to the list twice - if (!m_state_subscription || m_in_state_updates) return; + if (!m_state_subscription) return; + if (m_in_state_updates) + { + TORRENT_ASSERT(std::find_if(m_ses.m_state_updates.begin(), m_ses.m_state_updates.end() + , boost::bind(&boost::weak_ptr::lock, _1) == shared_from_this()) != m_ses.m_state_updates.end()); + return; + } m_ses.add_to_update_queue(shared_from_this()); m_in_state_updates = true;