diff --git a/libtorrent/include/libtorrent/disk_io_thread.hpp b/libtorrent/include/libtorrent/disk_io_thread.hpp index 23e8dd349..948db1176 100644 --- a/libtorrent/include/libtorrent/disk_io_thread.hpp +++ b/libtorrent/include/libtorrent/disk_io_thread.hpp @@ -88,6 +88,7 @@ namespace libtorrent , rename_file , abort_thread , clear_read_cache + , abort_torrent }; action_t action; diff --git a/libtorrent/include/libtorrent/storage.hpp b/libtorrent/include/libtorrent/storage.hpp index f144b5fc8..4f7cd5238 100644 --- a/libtorrent/include/libtorrent/storage.hpp +++ b/libtorrent/include/libtorrent/storage.hpp @@ -236,6 +236,8 @@ namespace libtorrent boost::function const& handler = boost::function()); + void abort_disk_io(); + void async_clear_read_cache( boost::function const& handler = boost::function()); diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index ab0fa2f74..dded34e79 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -178,7 +178,10 @@ namespace libtorrent } ++i; } - m_signal.notify_all(); + disk_io_job j; + j.action = disk_io_job::abort_torrent; + j.storage = s; + add_job(j); } bool range_overlap(int start1, int length1, int start2, int length2) @@ -802,6 +805,28 @@ namespace libtorrent switch (j.action) { + case disk_io_job::abort_torrent: + { + mutex_t::scoped_lock jl(m_queue_mutex); + for (std::list::iterator i = m_jobs.begin(); + i != m_jobs.end();) + { + if (i->storage != j.storage) + { + ++i; + continue; + } + if (i->action == disk_io_job::check_files) + { + if (i->callback) m_ios.post(bind(i->callback + , piece_manager::disk_check_aborted, *i)); + m_jobs.erase(i++); + continue; + } + ++i; + } + break; + } case disk_io_job::abort_thread: { mutex_t::scoped_lock jl(m_queue_mutex); diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index eda0b4368..376da677a 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -1331,6 +1331,11 @@ namespace libtorrent m_io_thread.add_job(j, handler); } + void piece_manager::abort_disk_io() + { + m_io_thread.stop(this); + } + void piece_manager::async_delete_files( boost::function const& handler) { diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 42c9e4f35..0f2036586 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1606,8 +1606,11 @@ namespace libtorrent // files belonging to the torrents disconnect_all(); if (m_owning_storage.get()) + { m_storage->async_release_files( bind(&torrent::on_files_released, shared_from_this(), _1, _2)); + m_storage->abort_disk_io(); + } if (m_state == torrent_status::checking_files) m_ses.done_checking(shared_from_this());