fixes #234. properly shuts down the disk io thread

This commit is contained in:
Arvid Norberg
2007-12-24 08:15:10 +00:00
parent 44735a425f
commit e0d1951fac
4 changed files with 20 additions and 7 deletions

View File

@@ -102,7 +102,9 @@ namespace libtorrent
int disk_allocations() const int disk_allocations() const
{ return m_allocations; } { return m_allocations; }
#endif #endif
void join();
// aborts read operations // aborts read operations
void stop(boost::intrusive_ptr<piece_manager> s); void stop(boost::intrusive_ptr<piece_manager> s);
void add_job(disk_io_job const& j void add_job(disk_io_job const& j

View File

@@ -62,12 +62,7 @@ namespace libtorrent
disk_io_thread::~disk_io_thread() disk_io_thread::~disk_io_thread()
{ {
mutex_t::scoped_lock l(m_mutex); TORRENT_ASSERT(m_abort == true);
m_abort = true;
m_signal.notify_all();
l.unlock();
m_disk_io_thread.join();
} }
#ifndef NDEBUG #ifndef NDEBUG
@@ -95,6 +90,16 @@ namespace libtorrent
#endif #endif
void disk_io_thread::join()
{
mutex_t::scoped_lock l(m_mutex);
m_abort = true;
m_signal.notify_all();
l.unlock();
m_disk_io_thread.join();
}
// aborts read operations // aborts read operations
void disk_io_thread::stop(boost::intrusive_ptr<piece_manager> s) void disk_io_thread::stop(boost::intrusive_ptr<piece_manager> s)
{ {

View File

@@ -2195,6 +2195,11 @@ namespace detail
#endif #endif
m_checker_thread->join(); m_checker_thread->join();
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_logger) << time_now_string() << " waiting for disk io thread\n";
#endif
m_disk_thread.join();
TORRENT_ASSERT(m_torrents.empty()); TORRENT_ASSERT(m_torrents.empty());
TORRENT_ASSERT(m_connections.empty()); TORRENT_ASSERT(m_connections.empty());
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)

View File

@@ -130,6 +130,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
pm->async_read(r, bind(&on_read_piece, _1, _2, piece2, piece_size)); pm->async_read(r, bind(&on_read_piece, _1, _2, piece2, piece_size));
pm->async_release_files(none); pm->async_release_files(none);
io.join();
} }
} }