simplify disk_io_thread interface by setting the number of threads via settings rather than a separate function
This commit is contained in:
parent
3ff89f29d7
commit
11ca69b9fc
|
@ -283,7 +283,6 @@ namespace libtorrent
|
|||
~disk_io_thread();
|
||||
|
||||
void set_settings(settings_pack const* sett, alert_manager& alerts);
|
||||
void set_num_threads(int i);
|
||||
|
||||
void abort(bool wait);
|
||||
|
||||
|
@ -357,9 +356,10 @@ namespace libtorrent
|
|||
{ return m_disk_cache.is_disk_buffer(buffer); }
|
||||
#endif
|
||||
|
||||
enum thread_type_t {
|
||||
generic_thread,
|
||||
hasher_thread
|
||||
enum class thread_type_t : std::uint8_t
|
||||
{
|
||||
generic,
|
||||
hasher
|
||||
};
|
||||
|
||||
void thread_fun(thread_type_t type, io_service::work w);
|
||||
|
|
|
@ -266,7 +266,6 @@ namespace libtorrent
|
|||
std::shared_ptr<char> dummy;
|
||||
counters cnt;
|
||||
disk_io_thread disk_thread(ios, cnt);
|
||||
disk_thread.set_num_threads(1);
|
||||
|
||||
storage_params params;
|
||||
params.files = &t.files();
|
||||
|
@ -282,7 +281,7 @@ namespace libtorrent
|
|||
|
||||
settings_pack sett;
|
||||
sett.set_int(settings_pack::cache_size, 0);
|
||||
sett.set_int(settings_pack::aio_threads, 2);
|
||||
sett.set_int(settings_pack::aio_threads, 1);
|
||||
|
||||
// TODO: this should probably be optional
|
||||
alert_manager dummy2(0, 0);
|
||||
|
|
|
@ -179,9 +179,9 @@ namespace libtorrent
|
|||
disk_io_thread::disk_io_thread(io_service& ios
|
||||
, counters& cnt
|
||||
, int const block_size)
|
||||
: m_generic_io_jobs(*this, generic_thread)
|
||||
: m_generic_io_jobs(*this, thread_type_t::generic)
|
||||
, m_generic_threads(m_generic_io_jobs, ios)
|
||||
, m_hash_io_jobs(*this, hasher_thread)
|
||||
, m_hash_io_jobs(*this, thread_type_t::hasher)
|
||||
, m_hash_threads(m_hash_io_jobs, ios)
|
||||
, m_last_file_check(clock_type::now())
|
||||
, m_disk_cache(block_size, ios, std::bind(&disk_io_thread::trigger_cache_trim, this))
|
||||
|
@ -240,17 +240,6 @@ namespace libtorrent
|
|||
m_hash_threads.abort(wait);
|
||||
}
|
||||
|
||||
// TODO: 1 it would be nice to have the number of threads be set dynamically
|
||||
void disk_io_thread::set_num_threads(int const i)
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
|
||||
// add one hasher thread for every three generic threads
|
||||
int const num_hash_threads = i / 4;
|
||||
m_generic_threads.set_max_threads(i - num_hash_threads);
|
||||
m_hash_threads.set_max_threads(num_hash_threads);
|
||||
}
|
||||
|
||||
void disk_io_thread::reclaim_blocks(span<block_cache_reference> refs)
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
|
@ -278,6 +267,12 @@ namespace libtorrent
|
|||
#else
|
||||
TORRENT_UNUSED(alerts);
|
||||
#endif
|
||||
|
||||
int const num_threads = m_settings.get_int(settings_pack::aio_threads);
|
||||
// add one hasher thread for every three generic threads
|
||||
int const num_hash_threads = num_threads / 4;
|
||||
m_generic_threads.set_max_threads(num_threads - num_hash_threads);
|
||||
m_hash_threads.set_max_threads(num_hash_threads);
|
||||
}
|
||||
|
||||
// flush all blocks that are below p->hash.offset, since we've
|
||||
|
@ -2986,13 +2981,13 @@ namespace libtorrent
|
|||
for (;;)
|
||||
{
|
||||
disk_io_job* j = nullptr;
|
||||
if (type == generic_thread)
|
||||
if (type == thread_type_t::generic)
|
||||
{
|
||||
bool const should_exit = wait_for_job(m_generic_io_jobs, m_generic_threads, l);
|
||||
if (should_exit) break;
|
||||
j = m_generic_io_jobs.m_queued_jobs.pop_front();
|
||||
}
|
||||
else if (type == hasher_thread)
|
||||
else if (type == thread_type_t::hasher)
|
||||
{
|
||||
bool const should_exit = wait_for_job(m_hash_io_jobs, m_hash_threads, l);
|
||||
if (should_exit) break;
|
||||
|
@ -3003,7 +2998,7 @@ namespace libtorrent
|
|||
|
||||
TORRENT_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage);
|
||||
|
||||
if (thread_id == m_generic_threads.first_thread_id() && type == generic_thread)
|
||||
if (thread_id == m_generic_threads.first_thread_id() && type == thread_type_t::generic)
|
||||
{
|
||||
// there's no need for all threads to be doing this
|
||||
maybe_flush_write_blocks();
|
||||
|
|
|
@ -1321,7 +1321,8 @@ namespace aux {
|
|||
m_disk_thread.set_settings(&pack, m_alerts);
|
||||
|
||||
if (init && !reopen_listen_port)
|
||||
{ // no need to call this if reopen_listen_port is true
|
||||
{
|
||||
// no need to call this if reopen_listen_port is true
|
||||
// since the apply_pack will do it
|
||||
update_listen_interfaces();
|
||||
}
|
||||
|
@ -5956,8 +5957,6 @@ namespace aux {
|
|||
if (m_settings.get_int(settings_pack::aio_threads) > 1)
|
||||
m_settings.set_int(settings_pack::aio_threads, 1);
|
||||
#endif
|
||||
|
||||
m_disk_thread.set_num_threads(m_settings.get_int(settings_pack::aio_threads));
|
||||
}
|
||||
|
||||
void session_impl::update_cache_buffer_chunk_size()
|
||||
|
|
|
@ -451,7 +451,12 @@ void test_check_files(std::string const& test_path
|
|||
boost::asio::io_service ios;
|
||||
counters cnt;
|
||||
disk_io_thread io(ios, cnt);
|
||||
io.set_num_threads(1);
|
||||
settings_pack sett;
|
||||
sett.set_int(settings_pack::aio_threads, 1);
|
||||
// TODO: this should probably be optional
|
||||
alert_manager dummy2(0, 0);
|
||||
io.set_settings(&sett, dummy2);
|
||||
|
||||
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
|
||||
storage_params p;
|
||||
p.files = &fs;
|
||||
|
|
Loading…
Reference in New Issue