From f9c12ef58913805368ef20c12b4eaea7ab2a889c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 23 May 2009 15:50:38 +0000 Subject: [PATCH] added more disk io asserts --- include/libtorrent/disk_io_thread.hpp | 2 ++ src/disk_io_thread.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 2869359b3..ef59929a3 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -171,6 +171,8 @@ namespace libtorrent #endif #ifdef TORRENT_DEBUG + bool is_disk_buffer(char* buffer + , boost::mutex::scoped_lock& l) const; bool is_disk_buffer(char* buffer) const; #endif diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 54b3a3006..be2f05850 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -77,13 +77,13 @@ namespace libtorrent #endif #ifdef TORRENT_DEBUG - bool disk_buffer_pool::is_disk_buffer(char* buffer) const + bool disk_buffer_pool::is_disk_buffer(char* buffer + ,boost::mutex::scoped_lock& l) const { TORRENT_ASSERT(m_magic == 0x1337); #ifdef TORRENT_DISABLE_POOL_ALLOCATOR return true; #else - mutex_t::scoped_lock l(m_pool_mutex); #ifdef TORRENT_DISK_STATS if (m_buf_to_category.find(buffer) == m_buf_to_category.end()) return false; @@ -91,6 +91,12 @@ namespace libtorrent return m_pool.is_from(buffer); #endif } + + bool disk_buffer_pool::is_disk_buffer(char* buffer) const + { + mutex_t::scoped_lock l(m_pool_mutex); + return is_disk_buffer(buffer, l); + } #endif char* disk_buffer_pool::allocate_buffer(char const* category) @@ -99,6 +105,7 @@ namespace libtorrent TORRENT_ASSERT(m_magic == 0x1337); #ifdef TORRENT_DISABLE_POOL_ALLOCATOR char* ret = page_aligned_allocator::malloc(m_block_size); + TORRENT_ASSERT(ret == 0 || is_disk_buffer(ret, l)); #else char* ret = (char*)m_pool.ordered_malloc(); m_pool.set_next_size(m_settings.cache_buffer_chunk_size); @@ -170,6 +177,7 @@ namespace libtorrent #ifdef TORRENT_DISABLE_POOL_ALLOCATOR page_aligned_allocator::free(buf); #else + TORRENT_ASSERT(is_disk_buffer(buf, l)); m_pool.ordered_free(buf); #endif --m_in_use;