expire read cache as well (same time out as write cache)
This commit is contained in:
parent
927f9623cb
commit
28cb451eac
|
@ -231,17 +231,32 @@ namespace libtorrent
|
||||||
mutex_t::scoped_lock l(m_piece_mutex);
|
mutex_t::scoped_lock l(m_piece_mutex);
|
||||||
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
// flush write cache
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
cache_t::iterator i = std::min_element(
|
cache_t::iterator i = std::min_element(
|
||||||
m_pieces.begin(), m_pieces.end()
|
m_pieces.begin(), m_pieces.end()
|
||||||
, bind(&cached_piece_entry::last_use, _1)
|
, bind(&cached_piece_entry::last_use, _1)
|
||||||
< bind(&cached_piece_entry::last_use, _2));
|
< 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);
|
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_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)
|
void disk_io_thread::free_piece(cached_piece_entry& p, mutex_t::scoped_lock& l)
|
||||||
|
|
Loading…
Reference in New Issue