From e071bf113edcad42b4aeadf0fb0d4374f21913d9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 21 Feb 2012 06:47:48 +0000 Subject: [PATCH] fixed connection_queue invariant check issue on shutdown --- src/connection_queue.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/connection_queue.cpp b/src/connection_queue.cpp index 320d995db..6b89ce7fd 100644 --- a/src/connection_queue.cpp +++ b/src/connection_queue.cpp @@ -134,27 +134,30 @@ namespace libtorrent if (m_num_connecting == 0) m_timer.cancel(ec); m_abort = true; - std::list to_keep; - while (!m_queue.empty()) + std::list tmp; + 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 - // since that is a recipie for dead-locks - entry e = m_queue.front(); - m_queue.pop_front(); + entry& e = tmp.front(); 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; } - if (e.connecting) --m_num_connecting; - l.unlock(); TORRENT_TRY { e.on_timeout(); } TORRENT_CATCH(std::exception&) {} - l.lock(); + tmp.pop_front(); } - - m_queue.swap(to_keep); } void connection_queue::limit(int limit)