disk_io_thread abort_hash_jobs duplicate code refactor
This commit is contained in:
parent
59d1c1f067
commit
2a82bb5880
|
@ -488,6 +488,7 @@ namespace aux {
|
||||||
void execute_job(disk_io_job* j);
|
void execute_job(disk_io_job* j);
|
||||||
void immediate_execute();
|
void immediate_execute();
|
||||||
void abort_jobs();
|
void abort_jobs();
|
||||||
|
void abort_hash_jobs(storage_index_t const storage);
|
||||||
|
|
||||||
// returns the maximum number of threads
|
// returns the maximum number of threads
|
||||||
// the actual number of threads may be less
|
// the actual number of threads may be less
|
||||||
|
|
|
@ -1830,25 +1830,25 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
|
||||||
add_fence_job(j);
|
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
|
void disk_io_thread::async_delete_files(storage_index_t const storage
|
||||||
, remove_flags_t const options
|
, remove_flags_t const options
|
||||||
, std::function<void(storage_error const&)> handler)
|
, std::function<void(storage_error const&)> handler)
|
||||||
{
|
{
|
||||||
{
|
abort_hash_jobs(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
disk_io_job* j = allocate_job(job_action_t::delete_files);
|
disk_io_job* j = allocate_job(job_action_t::delete_files);
|
||||||
j->storage = m_torrents[storage]->shared_from_this();
|
j->storage = m_torrents[storage]->shared_from_this();
|
||||||
j->callback = std::move(handler);
|
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
|
void disk_io_thread::async_stop_torrent(storage_index_t const storage
|
||||||
, std::function<void()> handler)
|
, std::function<void()> handler)
|
||||||
{
|
{
|
||||||
{
|
abort_hash_jobs(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disk_io_job* j = allocate_job(job_action_t::stop_torrent);
|
disk_io_job* j = allocate_job(job_action_t::stop_torrent);
|
||||||
j->storage = m_torrents[storage]->shared_from_this();
|
j->storage = m_torrents[storage]->shared_from_this();
|
||||||
j->callback = std::move(handler);
|
j->callback = std::move(handler);
|
||||||
|
|
Loading…
Reference in New Issue