record cache settings in the job instead of checking it twice for more robust behavior

This commit is contained in:
arvidn 2016-03-05 17:16:46 -05:00
parent 8ca76f9d59
commit a02c1d2164
3 changed files with 33 additions and 11 deletions

View File

@ -136,7 +136,11 @@ namespace libtorrent
in_progress = 0x20,
// turns into file::coalesce_buffers in the file operation
coalesce_buffers = 0x40
coalesce_buffers = 0x40,
// the disk cache was enabled when this job was issued, it should use
// the disk cache once it's handled by a disk thread
use_disk_cache = 0x80
};
// for write jobs, returns true if its block

View File

@ -441,3 +441,20 @@ TORRENT_TEST(auto_disk_cache_size)
}
);
}
TORRENT_TEST(disable_disk_cache)
{
using namespace libtorrent;
run_test(
[](lt::session& ses0, lt::session& ses1) { set_cache_size(ses0, 0); },
[](lt::session& ses, lt::alert const* alert) {},
[](std::shared_ptr<lt::session> ses[2]) {
TEST_EQUAL(is_seed(*ses[0]), true);
int const cache_size = get_cache_size(*ses[0]);
printf("cache size: %d\n", cache_size);
TEST_EQUAL(cache_size, 0);
}
);
}

View File

@ -1188,16 +1188,11 @@ namespace libtorrent
int disk_io_thread::do_read(disk_io_job* j, jobqueue_t& completed_jobs)
{
if (m_settings.get_bool(settings_pack::use_read_cache) == false
|| m_settings.get_int(settings_pack::cache_size) == 0)
if ((j->flags & disk_io_job::use_disk_cache) == 0)
{
// we're not using a cache. This is the simple path
// just read straight from the file
int ret = do_uncached_read(j);
mutex::scoped_lock l(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe) maybe_issue_queued_read_jobs(pe, completed_jobs);
return ret;
}
@ -1461,8 +1456,7 @@ namespace libtorrent
// should we put this write job in the cache?
// if we don't use the cache we shouldn't.
if (m_settings.get_bool(settings_pack::use_write_cache)
&& m_settings.get_int(settings_pack::cache_size) != 0)
if (j->flags & disk_io_job::use_disk_cache)
{
mutex::scoped_lock l(m_cache_mutex);
@ -1615,7 +1609,7 @@ namespace libtorrent
j->error.operation = storage_error::read;
return 0;
}
j->flags |= disk_io_job::use_disk_cache;
if (pe->outstanding_read)
{
TORRENT_PIECE_ASSERT(j->piece == pe->piece, pe);
@ -1695,6 +1689,7 @@ namespace libtorrent
&& m_settings.get_bool(settings_pack::use_write_cache))
{
TORRENT_ASSERT((r.start % m_disk_cache.block_size()) == 0);
j->flags |= disk_io_job::use_disk_cache;
if (storage->is_blocked(j))
{
@ -1784,6 +1779,12 @@ namespace libtorrent
}
l.unlock();
if (m_settings.get_bool(settings_pack::use_read_cache)
&& m_settings.get_int(settings_pack::cache_size) != 0)
{
j->flags |= disk_io_job::use_disk_cache;
}
add_job(j);
}
@ -2284,7 +2285,7 @@ namespace libtorrent
{
INVARIANT_CHECK;
if (m_settings.get_int(settings_pack::cache_size) == 0)
if ((j->flags & disk_io_job::use_disk_cache) == 0)
return do_uncached_hash(j);
int const piece_size = j->storage->files()->piece_size(j->piece);