From 6dbc7091d3d840d612222766488602e0ca78ed65 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 6 Jan 2014 03:50:25 +0000 Subject: [PATCH] fix link issue in build. caused corruption and crash in test_storage --- Jamfile | 44 +++++++++++++++++--------------- include/libtorrent/file_pool.hpp | 3 +++ src/allocator.cpp | 4 --- src/file_pool.cpp | 23 ++++++++++++++--- test/Jamfile | 2 +- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Jamfile b/Jamfile index cb8e976fe..bb1ee1486 100755 --- a/Jamfile +++ b/Jamfile @@ -25,6 +25,28 @@ if $(BOOST_ROOT) VERSION = 1.0.0 ; +rule coverage ( properties * ) +{ + local result ; + if gcc in $(properties) + || darwin in $(properties) + || clang in $(properties) + { + result += -fprofile-arcs -ftest-coverage ; + + if gcc in $(properties) + || darwin in $(properties) + { + result += -lgcov ; + } + else + { + result += --coverage ; + } + } + return $(result) ; +} + # rule for linking the correct libraries depending # on features and target-os rule linking ( properties * ) @@ -116,25 +138,6 @@ rule linking ( properties * ) result += libsocket libnsl ; } - if on in $(properties) - && ( gcc in $(properties) - || darwin in $(properties) - || clang in $(properties) ) - { - result += -fprofile-arcs -ftest-coverage - NDEBUG ; - - if gcc in $(properties) - || darwin in $(properties) - { - result += -lgcov ; - } - else - { - result += --coverage ; - } - } - # clock_gettime on linux requires librt if yes in $(properties) { @@ -367,7 +370,7 @@ feature.compose on : TORRENT_ASIO_DEBUGGING ; feature pool-allocators : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_POOL_ALLOCATOR ; -feature allocator : pool system debug : composite ; +feature allocator : pool system debug : composite propagated ; feature.compose system : TORRENT_DISABLE_POOL_ALLOCATOR ; feature.compose debug : TORRENT_DISABLE_POOL_ALLOCATOR TORRENT_DEBUG_BUFFERS ; @@ -431,6 +434,7 @@ feature debug-iterators : off on : composite propagated link-incompatible ; feature.compose on : _SCL_SECURE=1 _GLIBCXX_DEBUG ; feature test-coverage : off on : composite propagated ; +feature.compose on : @coverage ; feature fpic : off on : composite propagated link-incompatible ; feature.compose on : -fPIC ; diff --git a/include/libtorrent/file_pool.hpp b/include/libtorrent/file_pool.hpp index 0ff3c0059..ad1cb5d02 100644 --- a/include/libtorrent/file_pool.hpp +++ b/include/libtorrent/file_pool.hpp @@ -107,6 +107,9 @@ namespace libtorrent file_set m_files; mutex m_mutex; +#ifdef TORRENT_DEBUG + int m_in_use; +#endif #if TORRENT_CLOSE_MAY_BLOCK void closer_thread_fun(); diff --git a/src/allocator.cpp b/src/allocator.cpp index 6e5b2049f..4829665c9 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -72,10 +72,6 @@ struct alloc_header #endif -#if defined TORRENT_DEBUG_BUFFERS && (defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)) - void print_backtrace(char* out, int len, int max_depth = 0); -#endif - namespace libtorrent { diff --git a/src/file_pool.cpp b/src/file_pool.cpp index 2a3f04fc8..92c016dbf 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -48,10 +48,17 @@ namespace libtorrent , m_stop_thread(false) , m_closer_thread(boost::bind(&file_pool::closer_thread_fun, this)) #endif - {} + { +#ifdef TORRENT_DEBUG + m_in_use = 1337; +#endif + } file_pool::~file_pool() { +#ifdef TORRENT_DEBUG + m_in_use = 0; +#endif #if TORRENT_CLOSE_MAY_BLOCK mutex::scoped_lock l(m_closer_mutex); m_stop_thread = true; @@ -176,6 +183,7 @@ namespace libtorrent TORRENT_ASSERT((m & file::rw_mask) == file::read_only || (m & file::rw_mask) == file::read_write); mutex::scoped_lock l(m_mutex); + TORRENT_ASSERT(m_in_use == 1337); file_set::iterator i = m_files.find(std::make_pair(st, file_index)); if (i != m_files.end()) { @@ -260,15 +268,18 @@ namespace libtorrent void file_pool::remove_oldest() { + mutex::scoped_lock l(m_mutex); + TORRENT_ASSERT(m_in_use == 1337); + file_set::iterator i = std::min_element(m_files.begin(), m_files.end() , boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _1)) < boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _2))); if (i == m_files.end()) return; #if TORRENT_CLOSE_MAY_BLOCK - mutex::scoped_lock l(m_closer_mutex); + mutex::scoped_lock l_(m_closer_mutex); m_queued_for_close.push_back(i->second.file_ptr); - l.unlock(); + l_.unlock(); #endif m_files.erase(i); } @@ -276,6 +287,7 @@ namespace libtorrent void file_pool::release(void* st, int file_index) { mutex::scoped_lock l(m_mutex); + TORRENT_ASSERT(m_in_use == 1337); file_set::iterator i = m_files.find(std::make_pair(st, file_index)); if (i == m_files.end()) return; @@ -292,6 +304,7 @@ namespace libtorrent void file_pool::release(void* st) { mutex::scoped_lock l(m_mutex); + TORRENT_ASSERT(m_in_use == 1337); if (st == 0) { m_files.clear(); @@ -311,8 +324,10 @@ namespace libtorrent void file_pool::resize(int size) { TORRENT_ASSERT(size > 0); - if (size == m_size) return; + mutex::scoped_lock l(m_mutex); + TORRENT_ASSERT(m_in_use == 1337); + if (size == m_size) return; m_size = size; if (int(m_files.size()) <= m_size) return; diff --git a/test/Jamfile b/test/Jamfile index ca9759950..22f85c2f2 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -52,7 +52,7 @@ rule link_libtorrent ( properties * ) else { result += - /torrent//torrent/static/static/on/on ; + /torrent//torrent/static/static/on ; } return $(result) ; }