From ac8f64f5fe54f92b8b7456a3f9af23f954e4078d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 25 Dec 2009 16:02:45 +0000 Subject: [PATCH] fixed deadlock in piece_manager --- include/libtorrent/storage.hpp | 2 +- src/storage.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index d4b27173f..fde723deb 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -303,7 +303,7 @@ namespace libtorrent std::string name() const { return m_info->name(); } #endif - bool allocate_slots(int num_slots, bool abort_on_disk = false); + bool allocate_slots_impl(int num_slots, mutex::scoped_lock& l, bool abort_on_disk = false); // updates the ph.h hasher object with the data at the given slot // and optionally a 'small hash' as well, the hash for diff --git a/src/storage.cpp b/src/storage.cpp index bfe24d164..9c25c847e 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -2715,7 +2715,7 @@ ret: if (m_free_slots.empty()) { - allocate_slots(1); + allocate_slots_impl(1, lock); TORRENT_ASSERT(!m_free_slots.empty()); } @@ -2736,7 +2736,7 @@ ret: if (*iter == m_files.num_pieces() - 1 && piece_index != *iter) { if (m_free_slots.size() == 1) - allocate_slots(1); + allocate_slots_impl(1, lock); TORRENT_ASSERT(m_free_slots.size() > 1); // assumes that all allocated slots // are put at the end of the free_slots vector @@ -2807,9 +2807,9 @@ ret: return slot_index; } - bool piece_manager::allocate_slots(int num_slots, bool abort_on_disk) + bool piece_manager::allocate_slots_impl(int num_slots, mutex::scoped_lock& l + , bool abort_on_disk) { - mutex::scoped_lock lock(m_mutex); TORRENT_ASSERT(num_slots > 0); INVARIANT_CHECK;