remove use of disk_io_job from buffer_holder

This commit is contained in:
arvidn 2016-11-16 02:16:58 -05:00 committed by Arvid Norberg
parent 5b3a730b1f
commit 35126576ca
5 changed files with 14 additions and 15 deletions

View File

@ -78,7 +78,8 @@ namespace libtorrent
// construct a buffer holder that will free the held buffer
// using a disk buffer pool directly (there's only one
// disk_buffer_pool per session)
disk_buffer_holder(buffer_allocator_interface& alloc, disk_io_job const& j) noexcept;
disk_buffer_holder(buffer_allocator_interface& alloc
, block_cache_reference const& ref, char* buf) noexcept;
// frees any unreleased disk buffer held by this object
~disk_buffer_holder();
@ -95,7 +96,7 @@ namespace libtorrent
// (or nullptr by default). If it's already holding a
// disk buffer, it will first be freed.
void reset(char* buf = 0);
void reset(disk_io_job const& j);
void reset(block_cache_reference const& ref, char* buf);
// swap pointers of two disk buffer holders.
void swap(disk_buffer_holder& h) noexcept

View File

@ -57,8 +57,9 @@ namespace libtorrent
h.release();
}
disk_buffer_holder::disk_buffer_holder(buffer_allocator_interface& alloc, disk_io_job const& j) noexcept
: m_allocator(&alloc), m_buf(j.buffer.disk_block), m_ref(j.d.io.ref)
disk_buffer_holder::disk_buffer_holder(buffer_allocator_interface& alloc
, block_cache_reference const& ref, char* buf) noexcept
: m_allocator(&alloc), m_buf(buf), m_ref(ref)
{
TORRENT_ASSERT(m_ref.storage == nullptr || m_ref.piece >= 0);
TORRENT_ASSERT(m_ref.storage == nullptr || m_ref.block >= 0);
@ -66,24 +67,20 @@ namespace libtorrent
|| m_ref.piece < static_cast<storage_interface*>(m_ref.storage)->files()->num_pieces());
TORRENT_ASSERT(m_ref.storage == nullptr
|| m_ref.block <= static_cast<storage_interface*>(m_ref.storage)->files()->piece_length() / 0x4000);
TORRENT_ASSERT(j.action != disk_io_job::rename_file);
TORRENT_ASSERT(j.action != disk_io_job::move_storage);
}
void disk_buffer_holder::reset(disk_io_job const& j)
void disk_buffer_holder::reset(block_cache_reference const& ref, char* buf)
{
if (m_ref.storage) m_allocator->reclaim_blocks(m_ref);
else if (m_buf) m_allocator->free_disk_buffer(m_buf);
m_buf = j.buffer.disk_block;
m_ref = j.d.io.ref;
m_buf = buf;
m_ref = ref;
TORRENT_ASSERT(m_ref.piece >= 0);
TORRENT_ASSERT(m_ref.storage != nullptr);
TORRENT_ASSERT(m_ref.block >= 0);
TORRENT_ASSERT(m_ref.piece < static_cast<storage_interface*>(m_ref.storage)->files()->num_pieces());
TORRENT_ASSERT(m_ref.block <= static_cast<storage_interface*>(m_ref.storage)->files()->piece_length() / 0x4000);
TORRENT_ASSERT(j.action != disk_io_job::rename_file);
TORRENT_ASSERT(j.action != disk_io_job::move_storage);
}
void disk_buffer_holder::reset(char* const buf)

View File

@ -5274,7 +5274,7 @@ namespace libtorrent
// even if we're disconnecting, we need to free this block
// otherwise the disk thread will hang, waiting for the network
// thread to be done with it
disk_buffer_holder buffer(m_allocator, *j);
disk_buffer_holder buffer(m_allocator, j->d.io.ref, j->buffer.disk_block);
if (t && m_settings.get_int(settings_pack::suggest_mode)
== settings_pack::suggest_read_cache)

View File

@ -179,7 +179,7 @@ namespace
{
TORRENT_ASSERT(m_torrent.session().is_single_thread());
disk_buffer_holder buffer(m_torrent.session(), *j);
disk_buffer_holder buffer(m_torrent.session(), j->d.io.ref, j->buffer.disk_block);
// ignore read errors
if (j->ret != j->d.io.buffer_size) return;
@ -261,7 +261,7 @@ namespace
{
TORRENT_ASSERT(m_torrent.session().is_single_thread());
disk_buffer_holder buffer(m_torrent.session(), *j);
disk_buffer_holder buffer(m_torrent.session(), j->d.io.ref, j->buffer.disk_block);
// ignore read errors
if (j->ret != j->d.io.buffer_size) return;

View File

@ -1037,6 +1037,7 @@ namespace libtorrent
, peer_connection* c
, disk_class rw)
{
TORRENT_UNUSED(job_name);
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(error);
@ -1133,7 +1134,7 @@ namespace libtorrent
// hold a reference until this function returns
TORRENT_ASSERT(is_single_thread());
disk_buffer_holder buffer(m_ses, *j);
disk_buffer_holder buffer(m_ses, j->d.io.ref, j->buffer.disk_block);
--rp->blocks_left;
if (j->ret != r.length)