forked from premiere/premiere-libtorrent
remove use of disk_io_job from buffer_holder
This commit is contained in:
parent
5b3a730b1f
commit
35126576ca
|
@ -78,7 +78,8 @@ namespace libtorrent
|
||||||
// construct a buffer holder that will free the held buffer
|
// construct a buffer holder that will free the held buffer
|
||||||
// using a disk buffer pool directly (there's only one
|
// using a disk buffer pool directly (there's only one
|
||||||
// disk_buffer_pool per session)
|
// 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
|
// frees any unreleased disk buffer held by this object
|
||||||
~disk_buffer_holder();
|
~disk_buffer_holder();
|
||||||
|
@ -95,7 +96,7 @@ namespace libtorrent
|
||||||
// (or nullptr by default). If it's already holding a
|
// (or nullptr by default). If it's already holding a
|
||||||
// disk buffer, it will first be freed.
|
// disk buffer, it will first be freed.
|
||||||
void reset(char* buf = 0);
|
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.
|
// swap pointers of two disk buffer holders.
|
||||||
void swap(disk_buffer_holder& h) noexcept
|
void swap(disk_buffer_holder& h) noexcept
|
||||||
|
|
|
@ -57,8 +57,9 @@ namespace libtorrent
|
||||||
h.release();
|
h.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
disk_buffer_holder::disk_buffer_holder(buffer_allocator_interface& alloc, disk_io_job const& j) noexcept
|
disk_buffer_holder::disk_buffer_holder(buffer_allocator_interface& alloc
|
||||||
: m_allocator(&alloc), m_buf(j.buffer.disk_block), m_ref(j.d.io.ref)
|
, 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.piece >= 0);
|
||||||
TORRENT_ASSERT(m_ref.storage == nullptr || m_ref.block >= 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());
|
|| m_ref.piece < static_cast<storage_interface*>(m_ref.storage)->files()->num_pieces());
|
||||||
TORRENT_ASSERT(m_ref.storage == nullptr
|
TORRENT_ASSERT(m_ref.storage == nullptr
|
||||||
|| m_ref.block <= static_cast<storage_interface*>(m_ref.storage)->files()->piece_length() / 0x4000);
|
|| 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);
|
if (m_ref.storage) m_allocator->reclaim_blocks(m_ref);
|
||||||
else if (m_buf) m_allocator->free_disk_buffer(m_buf);
|
else if (m_buf) m_allocator->free_disk_buffer(m_buf);
|
||||||
m_buf = j.buffer.disk_block;
|
m_buf = buf;
|
||||||
m_ref = j.d.io.ref;
|
m_ref = ref;
|
||||||
|
|
||||||
TORRENT_ASSERT(m_ref.piece >= 0);
|
TORRENT_ASSERT(m_ref.piece >= 0);
|
||||||
TORRENT_ASSERT(m_ref.storage != nullptr);
|
TORRENT_ASSERT(m_ref.storage != nullptr);
|
||||||
TORRENT_ASSERT(m_ref.block >= 0);
|
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.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(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)
|
void disk_buffer_holder::reset(char* const buf)
|
||||||
|
|
|
@ -5274,7 +5274,7 @@ namespace libtorrent
|
||||||
// even if we're disconnecting, we need to free this block
|
// even if we're disconnecting, we need to free this block
|
||||||
// otherwise the disk thread will hang, waiting for the network
|
// otherwise the disk thread will hang, waiting for the network
|
||||||
// thread to be done with it
|
// 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)
|
if (t && m_settings.get_int(settings_pack::suggest_mode)
|
||||||
== settings_pack::suggest_read_cache)
|
== settings_pack::suggest_read_cache)
|
||||||
|
|
|
@ -179,7 +179,7 @@ namespace
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_torrent.session().is_single_thread());
|
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
|
// ignore read errors
|
||||||
if (j->ret != j->d.io.buffer_size) return;
|
if (j->ret != j->d.io.buffer_size) return;
|
||||||
|
@ -261,7 +261,7 @@ namespace
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_torrent.session().is_single_thread());
|
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
|
// ignore read errors
|
||||||
if (j->ret != j->d.io.buffer_size) return;
|
if (j->ret != j->d.io.buffer_size) return;
|
||||||
|
|
|
@ -1037,6 +1037,7 @@ namespace libtorrent
|
||||||
, peer_connection* c
|
, peer_connection* c
|
||||||
, disk_class rw)
|
, disk_class rw)
|
||||||
{
|
{
|
||||||
|
TORRENT_UNUSED(job_name);
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
TORRENT_ASSERT(error);
|
TORRENT_ASSERT(error);
|
||||||
|
|
||||||
|
@ -1133,7 +1134,7 @@ namespace libtorrent
|
||||||
// hold a reference until this function returns
|
// hold a reference until this function returns
|
||||||
TORRENT_ASSERT(is_single_thread());
|
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;
|
--rp->blocks_left;
|
||||||
if (j->ret != r.length)
|
if (j->ret != r.length)
|
||||||
|
|
Loading…
Reference in New Issue