more asserts around state updates

This commit is contained in:
Arvid Norberg 2012-01-20 05:40:32 +00:00
parent 48e7b35a93
commit ed56520d24
3 changed files with 17 additions and 3 deletions

View File

@ -503,7 +503,11 @@ namespace libtorrent
}
void add_to_update_queue(boost::weak_ptr<torrent> 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<torrent>::lock, _1) == t.lock()) == m_state_updates.end());
m_state_updates.push_back(t);
}
// private:

View File

@ -4548,6 +4548,10 @@ namespace aux {
void session_impl::post_torrent_updates()
{
INVARIANT_CHECK;
TORRENT_ASSERT(is_network_thread());
std::auto_ptr<state_update_alert> alert(new state_update_alert());
alert->status.reserve(m_state_updates.size());
@ -4557,8 +4561,8 @@ namespace aux {
boost::shared_ptr<torrent> 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();

View File

@ -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<torrent>::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;