disk_io_thread abort_hash_jobs duplicate code refactor

This commit is contained in:
gubatron 2018-04-04 23:55:23 -06:00 committed by Arvid Norberg
parent 59d1c1f067
commit 2a82bb5880
2 changed files with 17 additions and 29 deletions

View File

@ -488,6 +488,7 @@ namespace aux {
void execute_job(disk_io_job* j);
void immediate_execute();
void abort_jobs();
void abort_hash_jobs(storage_index_t const storage);
// returns the maximum number of threads
// the actual number of threads may be less

View File

@ -1830,25 +1830,25 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
add_fence_job(j);
}
void disk_io_thread::abort_hash_jobs(storage_index_t const storage) {
// abort outstanding hash jobs belonging to this torrent
std::unique_lock<std::mutex> l(m_job_mutex);
std::shared_ptr<storage_interface> st
= m_torrents[storage]->shared_from_this();
// hash jobs
for (auto i = m_hash_io_jobs.m_queued_jobs.iterate(); i.get(); i.next()) {
disk_io_job *j = i.get();
if (j->storage != st) continue;
j->flags |= disk_io_job::aborted;
}
}
void disk_io_thread::async_delete_files(storage_index_t const storage
, remove_flags_t const options
, std::function<void(storage_error const&)> handler)
{
{
// abort outstanding hash jobs belonging to this torrent
std::unique_lock<std::mutex> l(m_job_mutex);
std::shared_ptr<storage_interface> st
= m_torrents[storage]->shared_from_this();
// hash jobs
for (auto i = m_hash_io_jobs.m_queued_jobs.iterate(); i.get(); i.next())
{
disk_io_job* j = i.get();
if (j->storage != st) continue;
j->flags |= disk_io_job::aborted;
}
}
abort_hash_jobs(storage);
disk_io_job* j = allocate_job(job_action_t::delete_files);
j->storage = m_torrents[storage]->shared_from_this();
j->callback = std::move(handler);
@ -1888,20 +1888,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
void disk_io_thread::async_stop_torrent(storage_index_t const storage
, std::function<void()> handler)
{
{
// abort outstanding hash jobs belonging to this torrent
std::unique_lock<std::mutex> l(m_job_mutex);
std::shared_ptr<storage_interface> st
= m_torrents[storage]->shared_from_this();
// hash jobs
for (auto i = m_hash_io_jobs.m_queued_jobs.iterate(); i.get(); i.next())
{
disk_io_job* j = i.get();
if (j->storage != st) continue;
j->flags |= disk_io_job::aborted;
}
}
abort_hash_jobs(storage);
disk_io_job* j = allocate_job(job_action_t::stop_torrent);
j->storage = m_torrents[storage]->shared_from_this();
j->callback = std::move(handler);