expire read cache as well (same time out as write cache)

This commit is contained in:
Arvid Norberg 2008-12-27 02:38:14 +00:00
parent 927f9623cb
commit 28cb451eac
1 changed files with 17 additions and 2 deletions

View File

@ -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)