From d959331c1e478b23907e5abf5b9636d35afb6a4b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 17 Jan 2010 21:42:14 +0000 Subject: [PATCH] renamed some torrent check queue related functions to be more descriptive --- include/libtorrent/aux_/session_impl.hpp | 6 ++++-- src/session_impl.cpp | 9 +++++++-- src/torrent.cpp | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 9a3c84164..5a75c4584 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -232,8 +232,8 @@ namespace libtorrent std::vector get_torrents(); - void check_torrent(boost::shared_ptr const& t); - void done_checking(boost::shared_ptr const& t); + void queue_check_torrent(boost::shared_ptr const& t); + void dequeue_check_torrent(boost::shared_ptr const& t); void set_alert_mask(int m); size_t set_alert_queue_size_limit(size_t queue_size_limit_); @@ -496,6 +496,8 @@ namespace libtorrent tracker_manager m_tracker_manager; torrent_map m_torrents; typedef std::list > check_queue_t; + + // this has all torrents that wants to be checked in it check_queue_t m_queued_for_checking; // this maps sockets to their peer_connection diff --git a/src/session_impl.cpp b/src/session_impl.cpp index baf371cdc..ca1f412e3 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2634,7 +2634,7 @@ namespace aux { return torrent_handle(torrent_ptr); } - void session_impl::check_torrent(boost::shared_ptr const& t) + void session_impl::queue_check_torrent(boost::shared_ptr const& t) { if (m_abort) return; TORRENT_ASSERT(t->should_check_files()); @@ -2646,11 +2646,14 @@ namespace aux { m_queued_for_checking.push_back(t); } - void session_impl::done_checking(boost::shared_ptr const& t) + void session_impl::dequeue_check_torrent(boost::shared_ptr const& t) { INVARIANT_CHECK; + TORRENT_ASSERT(t->state() == torrent_status::checking_files + || t->state() == torrent_status::queued_for_checking); if (m_queued_for_checking.empty()) return; + boost::shared_ptr next_check = *m_queued_for_checking.begin(); check_queue_t::iterator done = m_queued_for_checking.end(); for (check_queue_t::iterator i = m_queued_for_checking.begin() @@ -2662,10 +2665,12 @@ namespace aux { next_check = *i; } // only start a new one if we removed the one that is checking + TORRENT_ASSERT(done != m_queued_for_checking.end()); if (done == m_queued_for_checking.end()) return; if (next_check != t && t->state() == torrent_status::checking_files) next_check->start_checking(); + m_queued_for_checking.erase(done); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 25867ee7f..a0fdaf33f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1014,14 +1014,14 @@ namespace libtorrent { if (m_queued_for_checking) return; m_queued_for_checking = true; - m_ses.check_torrent(shared_from_this()); + m_ses.queue_check_torrent(shared_from_this()); } void torrent::dequeue_torrent_check() { if (!m_queued_for_checking) return; m_queued_for_checking = false; - m_ses.done_checking(shared_from_this()); + m_ses.dequeue_check_torrent(shared_from_this()); } void torrent::force_recheck()