clears read cache when paused. Saves memory

This commit is contained in:
Arvid Norberg 2008-07-18 15:31:22 +00:00
parent d17d7d7b3f
commit 21dff61cb5
5 changed files with 48 additions and 0 deletions

View File

@ -86,6 +86,7 @@ namespace libtorrent
, save_resume_data
, rename_file
, abort_thread
, clear_read_cache
};
action_t action;

View File

@ -236,6 +236,10 @@ namespace libtorrent
boost::function<void(int, disk_io_job const&)> const& handler
= boost::function<void(int, disk_io_job const&)>());
void async_clear_read_cache(
boost::function<void(int, disk_io_job const&)> const& handler
= boost::function<void(int, disk_io_job const&)>());
void async_delete_files(
boost::function<void(int, disk_io_job const&)> const& handler
= boost::function<void(int, disk_io_job const&)>());

View File

@ -1003,6 +1003,39 @@ namespace libtorrent
if (ret != 0) test_error(j);
break;
}
case disk_io_job::clear_read_cache:
{
#ifdef TORRENT_DISK_STATS
m_log << log_time() << " clear-cache" << std::endl;
#endif
TORRENT_ASSERT(j.buffer == 0);
mutex_t::scoped_lock l(m_piece_mutex);
INVARIANT_CHECK;
for (cache_t::iterator i = m_read_pieces.begin();
i != m_read_pieces.end();)
{
if (i->storage == j.storage)
{
free_piece(*i, l);
i = m_read_pieces.erase(i);
}
else
{
++i;
}
}
l.unlock();
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
{
mutex_t::scoped_lock l(m_pool_mutex);
m_pool.release_memory();
}
#endif
ret = 0;
break;
}
case disk_io_job::delete_files:
{
#ifdef TORRENT_DISK_STATS

View File

@ -1275,6 +1275,15 @@ namespace libtorrent
m_io_thread.add_job(j, handler);
}
void piece_manager::async_clear_read_cache(
boost::function<void(int, disk_io_job const&)> const& handler)
{
disk_io_job j;
j.storage = this;
j.action = disk_io_job::clear_read_cache;
m_io_thread.add_job(j, handler);
}
void piece_manager::async_release_files(
boost::function<void(int, disk_io_job const&)> const& handler)
{

View File

@ -3753,6 +3753,7 @@ namespace libtorrent
TORRENT_ASSERT(m_storage);
m_storage->async_release_files(
bind(&torrent::on_torrent_paused, shared_from_this(), _1, _2));
m_storage->async_clear_read_cache();
}
else
{