forked from premiere/premiere-libtorrent
added option to not use pool allocators (useful when using memory debugging tools)
This commit is contained in:
parent
5a6e21f484
commit
75ef4ec1f1
3
Jamfile
3
Jamfile
|
@ -160,6 +160,9 @@ rule building ( properties * )
|
|||
|
||||
feature need-librt : no yes : composite propagated link-incompatible ;
|
||||
|
||||
feature pool-allocators : off static shared : composite propagated link-incompatible ;
|
||||
feature.compose <pool-allocators>off : <define>TORRENT_DISABLE_POOL_ALLOCATOR ;
|
||||
|
||||
feature geoip : off static shared : composite propagated link-incompatible ;
|
||||
feature.compose <geoip>off : <define>TORRENT_DISABLE_GEO_IP ;
|
||||
|
||||
|
|
|
@ -264,6 +264,12 @@ Build features:
|
|||
| | shipped public domain SHA-1 implementation is |
|
||||
| | used. |
|
||||
+------------------------+----------------------------------------------------+
|
||||
| ``pool-allocators`` | * ``on`` - default, uses pool allocators for send |
|
||||
| | buffers. |
|
||||
| | * ``off`` - uses ``malloc()`` and ``free()`` |
|
||||
| | instead. Might be useful to debug buffer issues |
|
||||
| | with tools like electric fence or libgmalloc. |
|
||||
+------------------------+----------------------------------------------------+
|
||||
| ``link`` | * ``static`` - builds libtorrent as a static |
|
||||
| | library (.a / .lib) |
|
||||
| | * ``shared`` - builds libtorrent as a shared |
|
||||
|
@ -540,6 +546,8 @@ defines you can use to control the build.
|
|||
| | will be built and the correct code will be |
|
||||
| | chosen at run-time. |
|
||||
+---------------------------------------+-------------------------------------------------+
|
||||
| ``TORRENT_DISABLE_POOL_ALLOCATOR`` | Disables use of ``boost::pool<>``. |
|
||||
+---------------------------------------+-------------------------------------------------+
|
||||
| ``TORRENT_LINKING_SHARED`` | If this is defined when including the |
|
||||
| | libtorrent headers, the classes and functions |
|
||||
| | will be tagged with ``__declspec(dllimport)`` |
|
||||
|
|
|
@ -343,9 +343,11 @@ namespace libtorrent
|
|||
|
||||
void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih);
|
||||
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
// this pool is used to allocate and recycle send
|
||||
// buffers from.
|
||||
boost::pool<> m_send_buffers;
|
||||
#endif
|
||||
boost::mutex m_send_buffer_mutex;
|
||||
|
||||
// the file pool that all storages in this session's
|
||||
|
|
|
@ -42,11 +42,13 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/function.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/pool/pool.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <list>
|
||||
#include "libtorrent/config.hpp"
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
#include <boost/pool/pool.hpp>
|
||||
#endif
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -259,9 +261,11 @@ namespace libtorrent
|
|||
bool m_coalesce_reads;
|
||||
bool m_use_read_cache;
|
||||
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
// memory pool for read and write operations
|
||||
// and disk cache
|
||||
boost::pool<> m_pool;
|
||||
#endif
|
||||
|
||||
// number of bytes per block. The BitTorrent
|
||||
// protocol defines the block size to 16 KiB.
|
||||
|
|
|
@ -55,7 +55,9 @@ namespace libtorrent
|
|||
, m_coalesce_writes(true)
|
||||
, m_coalesce_reads(true)
|
||||
, m_use_read_cache(true)
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
, m_pool(block_size)
|
||||
#endif
|
||||
, m_block_size(block_size)
|
||||
, m_ios(ios)
|
||||
, m_disk_io_thread(boost::ref(*this))
|
||||
|
@ -493,7 +495,9 @@ namespace libtorrent
|
|||
{
|
||||
if (p.blocks[k])
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
TORRENT_ASSERT(m_pool.is_from(p.blocks[k]));
|
||||
#endif
|
||||
++blocks;
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +519,9 @@ namespace libtorrent
|
|||
{
|
||||
if (p.blocks[k])
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
TORRENT_ASSERT(m_pool.is_from(p.blocks[k]));
|
||||
#endif
|
||||
++blocks;
|
||||
}
|
||||
}
|
||||
|
@ -690,7 +696,11 @@ namespace libtorrent
|
|||
#ifdef TORRENT_STATS
|
||||
++m_allocations;
|
||||
#endif
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
return (char*)malloc(m_block_size);
|
||||
#else
|
||||
return (char*)m_pool.ordered_malloc();
|
||||
#endif
|
||||
}
|
||||
|
||||
void disk_io_thread::free_buffer(char* buf, mutex_t::scoped_lock& l)
|
||||
|
@ -699,7 +709,11 @@ namespace libtorrent
|
|||
#ifdef TORRENT_STATS
|
||||
--m_allocations;
|
||||
#endif
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
free(buf);
|
||||
#else
|
||||
m_pool.ordered_free(buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void disk_io_thread::operator()()
|
||||
|
@ -738,7 +752,9 @@ namespace libtorrent
|
|||
std::string const& error_string = j.storage->error();
|
||||
if (!error_string.empty())
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
std::cout << "ERROR: " << error_string << std::endl;
|
||||
#endif
|
||||
j.str = error_string;
|
||||
j.storage->clear_error();
|
||||
ret = -1;
|
||||
|
@ -891,7 +907,9 @@ namespace libtorrent
|
|||
++i;
|
||||
}
|
||||
}
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
m_pool.release_memory();
|
||||
#endif
|
||||
l.unlock();
|
||||
ret = j.storage->release_files_impl();
|
||||
if (ret != 0)
|
||||
|
@ -925,7 +943,9 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
m_pieces.erase(i, m_pieces.end());
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
m_pool.release_memory();
|
||||
#endif
|
||||
l.unlock();
|
||||
ret = j.storage->delete_files_impl();
|
||||
if (ret != 0)
|
||||
|
|
|
@ -135,8 +135,11 @@ namespace aux {
|
|||
, fs::path const& logpath
|
||||
#endif
|
||||
)
|
||||
: m_send_buffers(send_buffer_size)
|
||||
, m_files(40)
|
||||
:
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
m_send_buffers(send_buffer_size),
|
||||
#endif
|
||||
m_files(40)
|
||||
, m_io_service()
|
||||
, m_disk_thread(m_io_service)
|
||||
, m_half_open(m_io_service)
|
||||
|
@ -2220,8 +2223,13 @@ namespace aux {
|
|||
m_buffer_usage_logger << log_time() << " protocol_buffer: "
|
||||
<< (m_buffer_allocations * send_buffer_size) << std::endl;
|
||||
#endif
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
int num_bytes = num_buffers * send_buffer_size;
|
||||
return std::make_pair((char*)malloc(num_bytes), num_bytes);
|
||||
#else
|
||||
return std::make_pair((char*)m_send_buffers.ordered_malloc(num_buffers)
|
||||
, num_buffers * send_buffer_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void session_impl::free_buffer(char* buf, int size)
|
||||
|
@ -2238,7 +2246,11 @@ namespace aux {
|
|||
m_buffer_usage_logger << log_time() << " protocol_buffer: "
|
||||
<< (m_buffer_allocations * send_buffer_size) << std::endl;
|
||||
#endif
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
free(buf);
|
||||
#else
|
||||
m_send_buffers.ordered_free(buf, num_buffers);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
|
Loading…
Reference in New Issue