From 28cb451eac009ce0d67c056e5486afe41636c4d9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 27 Dec 2008 02:38:14 +0000 Subject: [PATCH] expire read cache as well (same time out as write cache) --- src/disk_io_thread.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index de2343873..1ecda6f22 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -231,17 +231,32 @@ namespace libtorrent mutex_t::scoped_lock l(m_piece_mutex); INVARIANT_CHECK; + // flush write cache for (;;) { cache_t::iterator i = std::min_element( m_pieces.begin(), m_pieces.end() , bind(&cached_piece_entry::last_use, _1) < bind(&cached_piece_entry::last_use, _2)); - if (i == m_pieces.end()) return; + if (i == m_pieces.end()) break; int age = total_seconds(now - i->last_use); - if (age < m_cache_expiry) return; + if (age < m_cache_expiry) break; flush_and_remove(i, l); } + + // flush read cache + for (;;) + { + cache_t::iterator i = std::min_element( + m_read_pieces.begin(), m_read_pieces.end() + , bind(&cached_piece_entry::last_use, _1) + < bind(&cached_piece_entry::last_use, _2)); + if (i == m_read_pieces.end()) break; + int age = total_seconds(now - i->last_use); + if (age < m_cache_expiry) break; + free_piece(*i, l); + m_read_pieces.erase(i); + } } void disk_io_thread::free_piece(cached_piece_entry& p, mutex_t::scoped_lock& l)