From 54f0e6b91fed76ca5dda3d2a66744a432bfb1984 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 7 Oct 2007 23:54:04 +0000 Subject: [PATCH] fixed dead lock and fixed a problem in recent shutdown cleanup --- libtorrent/src/session_impl.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 3ae3839b4..83498ac14 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -337,11 +337,15 @@ namespace detail { TORRENT_ASSERT(!m_processing.empty()); TORRENT_ASSERT(m_processing.front() == processing); + m_processing.pop_front(); + // make sure the lock order is correct + l.unlock(); + session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + l.lock(); processing->torrent_ptr->abort(); processing.reset(); - m_processing.pop_front(); if (!m_processing.empty()) { processing = m_processing.front(); @@ -426,12 +430,13 @@ namespace detail processing->torrent_ptr->get_handle() , e.what())); } - TORRENT_ASSERT(!m_processing.empty()); processing->torrent_ptr->abort(); + if (!m_processing.empty() + && m_processing.front() == processing) + m_processing.pop_front(); processing.reset(); - m_processing.pop_front(); if (!m_processing.empty()) { processing = m_processing.front(); @@ -639,7 +644,6 @@ namespace detail { mutex_t::scoped_lock l(m_mutex); if (m_abort) return; - m_io_service.stop(); #if defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << " *** ABORT CALLED ***\n"; #endif @@ -659,6 +663,8 @@ namespace detail i->second->abort(); } + m_io_service.stop(); + mutex::scoped_lock l2(m_checker_impl.m_mutex); // abort the checker thread m_checker_impl.m_abort = true;