fixed connection_queue invariant check issue on shutdown

This commit is contained in:
Arvid Norberg
2012-02-21 06:47:48 +00:00
parent eef0f03343
commit e071bf113e

View File

@@ -134,27 +134,30 @@ namespace libtorrent
if (m_num_connecting == 0) m_timer.cancel(ec); if (m_num_connecting == 0) m_timer.cancel(ec);
m_abort = true; m_abort = true;
std::list<entry> to_keep; std::list<entry> tmp;
while (!m_queue.empty()) tmp.swap(m_queue);
m_num_connecting = 0;
// we don't want to call the timeout callback while we're locked
// since that is a recipie for dead-locks
l.unlock();
while (!tmp.empty())
{ {
// we don't want to call the timeout callback while we're locked entry& e = tmp.front();
// since that is a recipie for dead-locks
entry e = m_queue.front();
m_queue.pop_front();
if (e.priority > 1) if (e.priority > 1)
{ {
to_keep.push_back(e); mutex_t::scoped_lock ll(m_mutex);
if (e.connecting) ++m_num_connecting;
m_queue.push_back(e);
tmp.pop_front();
continue; continue;
} }
if (e.connecting) --m_num_connecting;
l.unlock();
TORRENT_TRY { TORRENT_TRY {
e.on_timeout(); e.on_timeout();
} TORRENT_CATCH(std::exception&) {} } TORRENT_CATCH(std::exception&) {}
l.lock(); tmp.pop_front();
} }
m_queue.swap(to_keep);
} }
void connection_queue::limit(int limit) void connection_queue::limit(int limit)