From 6e8db41dd23763265195120b00cb2e0732aa86e7 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 12 Mar 2016 19:06:01 -0800 Subject: [PATCH] check_cache_level after performing a job rather than before If dirty blocks are added while the job is running there is a chance of deadlock if the dirty blocks cause the cache to exceed its size limit and no further jobs come in to trigger another check. --- src/disk_io_thread.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 24e79b133..922ee82b2 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1087,18 +1087,18 @@ namespace libtorrent TORRENT_ASSERT(j->next == 0); TORRENT_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage); - mutex::scoped_lock l(m_cache_mutex); +#if DEBUG_DISK_THREAD + { + mutex::scoped_lock l(m_cache_mutex); - check_cache_level(l, completed_jobs); - - DLOG("perform_job job: %s ( %s%s) piece: %d offset: %d outstanding: %d\n" - , job_action_name[j->action] - , (j->flags & disk_io_job::fence) ? "fence ": "" - , (j->flags & disk_io_job::force_copy) ? "force_copy ": "" - , j->piece, j->d.io.offset - , j->storage ? j->storage->num_outstanding_jobs() : -1); - - l.unlock(); + DLOG("perform_job job: %s ( %s%s) piece: %d offset: %d outstanding: %d\n" + , job_action_name[j->action] + , (j->flags & disk_io_job::fence) ? "fence ": "" + , (j->flags & disk_io_job::force_copy) ? "force_copy ": "" + , j->piece, j->d.io.offset + , j->storage ? j->storage->num_outstanding_jobs() : -1); + } +#endif boost::shared_ptr storage = j->storage; @@ -1123,6 +1123,10 @@ namespace libtorrent m_stats_counters.inc_stats_counter(counters::num_running_disk_jobs, -1); + mutex::scoped_lock l(m_cache_mutex); + check_cache_level(l, completed_jobs); + l.unlock(); + if (ret == retry_job) { mutex::scoped_lock l2(m_job_mutex);