From 317eb2fe2ac8c56dabad27da177e45d512b570c5 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 16 Mar 2016 20:13:28 -0400 Subject: [PATCH] remove unused disk allocation code --- include/libtorrent/aux_/session_impl.hpp | 2 - include/libtorrent/disk_buffer_holder.hpp | 2 - include/libtorrent/disk_buffer_pool.hpp | 9 --- include/libtorrent/disk_io_thread.hpp | 3 +- src/disk_buffer_pool.cpp | 72 +---------------------- src/disk_io_thread.cpp | 4 -- src/peer_connection.cpp | 22 ------- src/session_impl.cpp | 6 -- 8 files changed, 4 insertions(+), 116 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 76d30ffb3..186dbfc42 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -563,8 +563,6 @@ namespace libtorrent char* allocate_disk_buffer(bool& exceeded , boost::shared_ptr o , char const* category) TORRENT_OVERRIDE; - char* async_allocate_disk_buffer(char const* category - , boost::function const& handler) TORRENT_OVERRIDE; void reclaim_block(block_cache_reference ref) TORRENT_OVERRIDE; bool exceeded_cache_use() const diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index f4d660059..0e7e3d94e 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -58,8 +58,6 @@ namespace libtorrent virtual char* allocate_disk_buffer(bool& exceeded , boost::shared_ptr o , char const* category) = 0; - virtual char* async_allocate_disk_buffer(char const* category - , boost::function const& handler) = 0; protected: ~buffer_allocator_interface() {} }; diff --git a/include/libtorrent/disk_buffer_pool.hpp b/include/libtorrent/disk_buffer_pool.hpp index 1f5545d11..035f40b91 100644 --- a/include/libtorrent/disk_buffer_pool.hpp +++ b/include/libtorrent/disk_buffer_pool.hpp @@ -75,11 +75,6 @@ namespace libtorrent bool is_disk_buffer(char* buffer) const; #endif - // tries to allocate a disk buffer. If the cache is full, this function will - // return NULL and call the disk_observer once a buffer becomes available - char* async_allocate_buffer(char const* category - , boost::function const& handler); - char* allocate_buffer(char const* category); char* allocate_buffer(bool& exceeded, boost::shared_ptr o , char const* category); @@ -134,12 +129,8 @@ namespace libtorrent // adding up callbacks to this queue. Once the number // of buffers in use drops below the low watermark, // we start calling these functions back - // TODO: try to remove the observers, only using the async_allocate handlers std::vector > m_observers; - // these handlers are executed when a new buffer is available - std::vector m_handlers; - // callback used to tell the cache it needs to free up some blocks boost::function m_trigger_cache_trim; diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 0c55e2726..da302f9c9 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -362,8 +362,7 @@ namespace libtorrent void trigger_cache_trim(); char* allocate_disk_buffer(bool& exceeded, boost::shared_ptr o - , char const* category); - char* async_allocate_disk_buffer(char const* category, boost::function const& handler); + , char const* category) TORRENT_OVERRIDE; bool exceeded_cache_use() const { return m_disk_cache.exceeded_max_size(); } diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 1bfeefd26..274f5e4f4 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -67,17 +67,8 @@ namespace libtorrent namespace { // this is posted to the network thread - void watermark_callback(std::vector >* cbs - , std::vector* handlers) + void watermark_callback(std::vector >* cbs) { - if (handlers) - { - for (std::vector::iterator i = handlers->begin() - , end(handlers->end()); i != end; ++i) - i->callback(i->buffer); - delete handlers; - } - if (cbs != NULL) { for (std::vector >::iterator i = cbs->begin() @@ -147,7 +138,7 @@ namespace libtorrent mutex::scoped_lock l(m_pool_mutex); if (m_exceeded_max_size) - ret = m_in_use - (std::min)(m_low_watermark, int(m_max_use - (m_observers.size() + m_handlers.size())*2)); + ret = m_in_use - (std::min)(m_low_watermark, int(m_max_use - m_observers.size()*2)); if (m_in_use + num_needed > m_max_use) ret = (std::max)(ret, int(m_in_use + num_needed - m_max_use)); @@ -169,49 +160,11 @@ namespace libtorrent m_exceeded_max_size = false; - // if slice is non-NULL, only some of the handlers got a buffer - // back, and the slice should be posted back to the network thread - std::vector* slice = NULL; - - for (std::vector::iterator i = m_handlers.begin() - , end(m_handlers.end()); i != end; ++i) - { - i->buffer = allocate_buffer_impl(l, i->category); - if (!m_exceeded_max_size || i == end - 1) continue; - - // only some of the handlers got buffers. We need to slice the vector - slice = new std::vector(); - slice->insert(slice->end(), m_handlers.begin(), i + 1); - m_handlers.erase(m_handlers.begin(), i + 1); - break; - } - - if (slice != NULL) - { - l.unlock(); - m_ios.post(boost::bind(&watermark_callback - , static_cast >*>(NULL) - , slice)); - return; - } - - std::vector* handlers = new std::vector(); - handlers->swap(m_handlers); - - if (m_exceeded_max_size) - { - l.unlock(); - m_ios.post(boost::bind(&watermark_callback - , static_cast >*>(NULL) - , handlers)); - return; - } - std::vector >* cbs = new std::vector >(); m_observers.swap(*cbs); l.unlock(); - m_ios.post(boost::bind(&watermark_callback, cbs, handlers)); + m_ios.post(boost::bind(&watermark_callback, cbs)); } #if TORRENT_USE_ASSERTS @@ -251,25 +204,6 @@ namespace libtorrent } #endif - char* disk_buffer_pool::async_allocate_buffer(char const* category - , boost::function const& handler) - { - mutex::scoped_lock l(m_pool_mutex); - if (m_exceeded_max_size) - { - m_handlers.push_back(handler_t()); - handler_t& h = m_handlers.back(); - h.category = category; - h.callback = handler; - h.buffer = NULL; - return NULL; - } - - char* ret = allocate_buffer_impl(l, category); - - return ret; - } - char* disk_buffer_pool::allocate_buffer(char const* category) { mutex::scoped_lock l(m_pool_mutex); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 7810cbcc9..62f5fa1a5 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -261,10 +261,6 @@ namespace libtorrent } } - char* disk_io_thread::async_allocate_disk_buffer(char const* category - , boost::function const& handler) - { return m_disk_cache.async_allocate_buffer(category, handler); } - void disk_io_thread::reclaim_block(block_cache_reference ref) { TORRENT_ASSERT(m_magic == 0x1337); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 0ba41cba5..ec8b0431b 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -6289,28 +6289,6 @@ namespace libtorrent // cache space right now if (m_channel_state[download_channel] & peer_info::bw_disk) return false; -/* - // if we already have a disk buffer, we might as well use it - // if contiguous recv buffer is true, don't apply this logic, but - // actually wait until we try to allocate a buffer and exceed the limit - if (m_disk_recv_buffer == NULL - && !m_settings.get_bool(settings_pack::contiguous_recv_buffer)) - { - m_disk_recv_buffer.reset(m_ses.async_allocate_disk_buffer("receive buffer", - boost::bind(&peer_connection::on_allocate_disk_buffer, self(), _1, #error buffer_size))); - - if (m_disk_recv_buffer == NULL) - { - m_counters.inc_stats_counter(counters::num_peers_down_disk); - const_cast(this)->m_channel_state[download_channel] |= peer_info::bw_disk; - -#ifndef TORRENT_DISABLE_LOGGING - peer_log(peer_log_alert::info, "DISK", "exceeded disk buffer watermark"); -#endif - return false; - } - } -*/ } return !m_connecting && !m_disconnecting; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9ae687d63..958a78347 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6924,12 +6924,6 @@ retry: return m_disk_thread.allocate_disk_buffer(category); } - char* session_impl::async_allocate_disk_buffer(char const* category - , boost::function const& handler) - { - return m_disk_thread.async_allocate_disk_buffer(category, handler); - } - void session_impl::free_disk_buffer(char* buf) { m_disk_thread.free_disk_buffer(buf);