diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index 9eb765690..7335c5e25 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -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 diff --git a/src/disk_buffer_holder.cpp b/src/disk_buffer_holder.cpp index 7ab24b1e7..a7408556d 100644 --- a/src/disk_buffer_holder.cpp +++ b/src/disk_buffer_holder.cpp @@ -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(m_ref.storage)->files()->num_pieces()); TORRENT_ASSERT(m_ref.storage == nullptr || m_ref.block <= static_cast(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(m_ref.storage)->files()->num_pieces()); TORRENT_ASSERT(m_ref.block <= static_cast(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) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 25138d7ec..9d59497ca 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -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) diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index f13e60be3..320e84da2 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -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; diff --git a/src/torrent.cpp b/src/torrent.cpp index bbe808ee7..4f4cd57a8 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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)