move block_cache_reference out of disk_io_job header

This commit is contained in:
arvidn 2016-11-18 00:25:27 -05:00 committed by Arvid Norberg
parent 35126576ca
commit d5b76d2237
20 changed files with 107 additions and 50 deletions

View File

@ -158,6 +158,7 @@ nobase_include_HEADERS = \
\
aux_/allocating_handler.hpp \
aux_/bind_to_device.hpp \
aux_/block_cache_reference.hpp \
aux_/cpuid.hpp \
aux_/disable_warnings_push.hpp \
aux_/disable_warnings_pop.hpp \

View File

@ -0,0 +1,50 @@
/*
Copyright (c) 2010-2016, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_BLOCK_CACHE_REFERENCE_HPP
#define TORRENT_BLOCK_CACHE_REFERENCE_HPP
namespace libtorrent {
namespace aux {
struct block_cache_reference
{
void* storage;
int piece;
int block;
};
}
}
#endif

View File

@ -39,14 +39,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/error_code.hpp"
#include <functional>
#include <memory>
#ifndef TORRENT_DISABLE_DHT
#include "libtorrent/socket.hpp"
#endif
#include "libtorrent/socket.hpp" // for tcp::endpoint
#include "libtorrent/aux_/disable_warnings_push.hpp"

View File

@ -54,9 +54,12 @@ namespace libtorrent
struct disk_io_job;
struct storage_interface;
struct cache_status;
struct block_cache_reference;
struct counters;
namespace aux { struct session_settings; }
namespace aux
{
struct session_settings;
struct block_cache_reference;
}
#if TORRENT_USE_ASSERTS
class file_storage;
#endif
@ -346,7 +349,7 @@ namespace libtorrent
int pad_job(disk_io_job const* j, int blocks_in_piece
, int read_ahead) const;
void reclaim_block(block_cache_reference const& ref);
void reclaim_block(aux::block_cache_reference const& ref);
// returns a range of all pieces. This might be a very
// long list, use carefully
@ -408,7 +411,7 @@ namespace libtorrent
// looks for this piece in the cache. If it's there, returns a pointer
// to it, otherwise 0.
cached_piece_entry* find_piece(block_cache_reference const& ref);
cached_piece_entry* find_piece(aux::block_cache_reference const& ref);
cached_piece_entry* find_piece(disk_io_job const* j);
cached_piece_entry* find_piece(storage_interface* st, int piece);

View File

@ -315,8 +315,8 @@ public:
// peer_connection functions of the same names
virtual void append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference()) override;
, void* userdata = nullptr, aux::block_cache_reference ref
= aux::block_cache_reference()) override;
private:

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_CHAINED_BUFFER_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/disk_io_job.hpp" // for block_cache_reference
#include "libtorrent/aux_/block_cache_reference.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/buffer.hpp"
@ -60,7 +60,7 @@ namespace libtorrent
// destructs/frees the buffer (1st arg) with
// 2nd argument as userdata
typedef void (*free_buffer_fun)(char*, void*, block_cache_reference ref);
typedef void (*free_buffer_fun)(char*, void*, aux::block_cache_reference ref);
struct buffer_t
{
@ -73,7 +73,7 @@ namespace libtorrent
char* start; // the first byte to send/receive in the buffer
int size; // the total size of the buffer
int used_size; // this is the number of bytes to send/receive
block_cache_reference ref;
aux::block_cache_reference ref;
};
bool empty() const { return m_bytes == 0; }
@ -85,11 +85,11 @@ namespace libtorrent
//TODO: 3 use span<> instead of (buffer,s)
void append_buffer(char* buffer, int s, int used_size
, free_buffer_fun destructor, void* userdata
, block_cache_reference ref = block_cache_reference());
, aux::block_cache_reference ref = aux::block_cache_reference());
void prepend_buffer(char* buffer, int s, int used_size
, free_buffer_fun destructor, void* userdata
, block_cache_reference ref = block_cache_reference());
, aux::block_cache_reference ref = aux::block_cache_reference());
// returns the number of bytes available at the
// end of the last chained buffer.

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/disk_io_job.hpp" // for block_cache_reference
#include "libtorrent/aux_/block_cache_reference.hpp"
#include "libtorrent/span.hpp"
#include <memory>
@ -49,7 +49,7 @@ namespace libtorrent
struct TORRENT_EXTRA_EXPORT buffer_allocator_interface
{
virtual void free_disk_buffer(char* b) = 0;
virtual void reclaim_blocks(span<block_cache_reference> refs) = 0;
virtual void reclaim_blocks(span<aux::block_cache_reference> refs) = 0;
virtual disk_buffer_holder allocate_disk_buffer(char const* category) = 0;
virtual disk_buffer_holder allocate_disk_buffer(bool& exceeded
, std::shared_ptr<disk_observer> o
@ -79,7 +79,7 @@ namespace libtorrent
// using a disk buffer pool directly (there's only one
// disk_buffer_pool per session)
disk_buffer_holder(buffer_allocator_interface& alloc
, block_cache_reference const& ref, char* buf) noexcept;
, aux::block_cache_reference const& ref, char* buf) noexcept;
// frees any unreleased disk buffer held by this object
~disk_buffer_holder();
@ -96,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(block_cache_reference const& ref, char* buf);
void reset(aux::block_cache_reference const& ref, char* buf);
// swap pointers of two disk buffer holders.
void swap(disk_buffer_holder& h) noexcept
@ -106,7 +106,7 @@ namespace libtorrent
std::swap(h.m_ref, m_ref);
}
block_cache_reference ref() const noexcept { return m_ref; }
aux::block_cache_reference ref() const noexcept { return m_ref; }
// implicitly convertible to true if the object is currently holding a
// buffer
@ -116,7 +116,7 @@ namespace libtorrent
buffer_allocator_interface* m_allocator;
char* m_buf;
block_cache_reference m_ref;
aux::block_cache_reference m_ref;
};
}

View File

@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/tailqueue.hpp"
#include "libtorrent/aux_/block_cache_reference.hpp"
#include <string>
#include <vector>
@ -48,13 +49,6 @@ namespace libtorrent
class torrent_info;
struct add_torrent_params;
struct block_cache_reference
{
void* storage;
int piece;
int block;
};
// disk_io_jobs are allocated in a pool allocator in disk_io_thread
// they are always allocated from the network thread, posted
// (as pointers) to the disk I/O thread, and then passed back
@ -178,7 +172,7 @@ namespace libtorrent
// is set in a response to a read, the buffer needs to
// be de-referenced by sending a reclaim_block message
// back to the disk thread
block_cache_reference ref;
aux::block_cache_reference ref;
// for read and write, the offset into the piece
// the read or write should start

View File

@ -60,6 +60,11 @@ namespace libtorrent
struct counters;
class alert_manager;
namespace aux
{
struct block_cache_reference;
}
struct cached_piece_info
{
storage_interface* storage;
@ -327,7 +332,7 @@ namespace libtorrent
void clear_piece(storage_interface* storage, int index) override;
// implements buffer_allocator_interface
void reclaim_blocks(span<block_cache_reference> ref) override;
void reclaim_blocks(span<aux::block_cache_reference> ref) override;
void free_disk_buffer(char* buf) override { m_disk_cache.free_buffer(buf); }
disk_buffer_holder allocate_disk_buffer(char const* category) override
{

View File

@ -164,6 +164,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/string_view.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/error_code.hpp"
namespace libtorrent
{

View File

@ -148,7 +148,7 @@ namespace libtorrent
};
// internal
inline void nop(char*, void*, block_cache_reference) {}
inline void nop(char*, void*, aux::block_cache_reference) {}
struct TORRENT_EXTRA_EXPORT peer_connection_hot_members
{
@ -630,13 +630,13 @@ namespace libtorrent
void append_send_buffer(char* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference());
, void* userdata = nullptr, aux::block_cache_reference ref
= aux::block_cache_reference());
virtual void append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference());
, void* userdata = nullptr, aux::block_cache_reference ref
= aux::block_cache_reference());
int outstanding_bytes() const { return m_outstanding_bytes; }

View File

@ -54,6 +54,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bitfield.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/tailqueue.hpp"
#include "libtorrent/disk_io_job.hpp"
// OVERVIEW
//

View File

@ -92,6 +92,7 @@ namespace libtorrent
struct storage_interface;
class bt_peer_connection;
struct listen_socket_t;
struct disk_io_job;
enum class waste_reason
{

View File

@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alloca.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/aux_/block_cache_reference.hpp"
/*
@ -1779,7 +1780,7 @@ int block_cache::copy_from_piece(cached_piece_entry* const pe
return j->d.io.buffer_size;
}
void block_cache::reclaim_block(block_cache_reference const& ref)
void block_cache::reclaim_block(aux::block_cache_reference const& ref)
{
cached_piece_entry* pe = find_piece(ref);
TORRENT_ASSERT(pe);
@ -1817,7 +1818,7 @@ bool block_cache::maybe_free_piece(cached_piece_entry* pe)
return true;
}
cached_piece_entry* block_cache::find_piece(block_cache_reference const& ref)
cached_piece_entry* block_cache::find_piece(aux::block_cache_reference const& ref)
{
return find_piece(static_cast<storage_interface*>(ref.storage), ref.piece);
}

View File

@ -725,7 +725,7 @@ namespace libtorrent
namespace {
void regular_c_free(char* buf, void* /* userdata */
, block_cache_reference /* ref */)
, aux::block_cache_reference /* ref */)
{
std::free(buf);
}
@ -735,7 +735,7 @@ namespace libtorrent
void bt_peer_connection::append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
if (!m_enc_handler.is_send_plaintext())
@ -2433,14 +2433,14 @@ namespace libtorrent
namespace {
void buffer_reclaim_block(char* /* buffer */, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
buffer_allocator_interface* buf = static_cast<buffer_allocator_interface*>(userdata);
buf->reclaim_blocks(ref);
}
void buffer_free_disk_buf(char* buffer, void* userdata
, block_cache_reference /* ref */)
, aux::block_cache_reference /* ref */)
{
buffer_allocator_interface* buf = static_cast<buffer_allocator_interface*>(userdata);
buf->free_disk_buffer(buffer);

View File

@ -68,7 +68,7 @@ namespace libtorrent
void chained_buffer::append_buffer(char* buffer, int s, int used_size
, free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(s >= used_size);
@ -89,7 +89,7 @@ namespace libtorrent
void chained_buffer::prepend_buffer(char* buffer, int s, int used_size
, free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
TORRENT_ASSERT(s >= used_size);
buffer_t b;

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/storage.hpp" // for storage_interface
#include "libtorrent/aux_/block_cache_reference.hpp"
namespace libtorrent
{
@ -58,7 +59,7 @@ namespace libtorrent
}
disk_buffer_holder::disk_buffer_holder(buffer_allocator_interface& alloc
, block_cache_reference const& ref, char* buf) noexcept
, aux::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);
@ -69,7 +70,7 @@ namespace libtorrent
|| m_ref.block <= static_cast<storage_interface*>(m_ref.storage)->files()->piece_length() / 0x4000);
}
void disk_buffer_holder::reset(block_cache_reference const& ref, char* buf)
void disk_buffer_holder::reset(aux::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);

View File

@ -239,7 +239,7 @@ namespace libtorrent
m_hash_threads.abort(wait);
}
void disk_io_thread::reclaim_blocks(span<block_cache_reference> refs)
void disk_io_thread::reclaim_blocks(span<aux::block_cache_reference> refs)
{
TORRENT_ASSERT(m_magic == 0x1337);

View File

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/kademlia/node_id.hpp"
#include "libtorrent/close_reason.hpp"
#include "libtorrent/disk_io_job.hpp"
#include "libtorrent/aux_/has_block.hpp"
#include "libtorrent/aux_/time.hpp"
@ -5676,7 +5677,7 @@ namespace libtorrent
void peer_connection::append_send_buffer(char* buffer, int size
, chained_buffer::free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
TORRENT_ASSERT(is_single_thread());
m_send_buffer.append_buffer(buffer, size, size, destructor
@ -5685,7 +5686,7 @@ namespace libtorrent
void peer_connection::append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
, aux::block_cache_reference ref)
{
TORRENT_ASSERT(is_single_thread());
m_send_buffer.append_buffer(const_cast<char*>(buffer), size, size, destructor
@ -5702,7 +5703,7 @@ namespace libtorrent
}
namespace {
void session_free_buffer(char* buffer, void* userdata, block_cache_reference)
void session_free_buffer(char* buffer, void* userdata, aux::block_cache_reference)
{
aux::session_interface* ses = static_cast<aux::session_interface*>(userdata);
ses->free_buffer(buffer);

View File

@ -140,7 +140,7 @@ TORRENT_TEST(buffer_move_assign)
std::set<char*> buffer_list;
void free_buffer(char* m, void* userdata, block_cache_reference ref)
void free_buffer(char* m, void* userdata, aux::block_cache_reference ref)
{
TEST_CHECK(userdata == (void*)0x1337);
std::set<char*>::iterator i = buffer_list.find(m);