forked from premiere/premiere-libtorrent
more asserts around send buffers and fixes potential race condition
This commit is contained in:
parent
8a47c849ce
commit
cfe5c8962e
|
@ -382,6 +382,7 @@ namespace libtorrent
|
|||
// this pool is used to allocate and recycle send
|
||||
// buffers from.
|
||||
boost::pool<> m_send_buffers;
|
||||
boost::mutex m_send_buffer_mutex;
|
||||
|
||||
// the file pool that all storages in this session's
|
||||
// torrents uses. It sets a limit on the number of
|
||||
|
|
|
@ -2607,6 +2607,7 @@ namespace libtorrent
|
|||
// return value is destructed
|
||||
buffer::interval peer_connection::allocate_send_buffer(int size)
|
||||
{
|
||||
TORRENT_ASSERT(size > 0);
|
||||
char* insert = m_send_buffer.allocate_appendix(size);
|
||||
if (insert == 0)
|
||||
{
|
||||
|
|
|
@ -2388,7 +2388,11 @@ namespace detail
|
|||
|
||||
std::pair<char*, int> session_impl::allocate_buffer(int size)
|
||||
{
|
||||
TORRENT_ASSERT(size > 0);
|
||||
int num_buffers = (size + send_buffer_size - 1) / send_buffer_size;
|
||||
TORRENT_ASSERT(num_buffers > 0);
|
||||
|
||||
boost::mutex::scoped_lock l(m_send_buffer_mutex);
|
||||
#ifdef TORRENT_STATS
|
||||
m_buffer_allocations += num_buffers;
|
||||
m_buffer_usage_logger << log_time() << " protocol_buffer: "
|
||||
|
@ -2400,8 +2404,12 @@ namespace detail
|
|||
|
||||
void session_impl::free_buffer(char* buf, int size)
|
||||
{
|
||||
TORRENT_ASSERT(size > 0);
|
||||
TORRENT_ASSERT(size % send_buffer_size == 0);
|
||||
int num_buffers = size / send_buffer_size;
|
||||
TORRENT_ASSERT(num_buffers > 0);
|
||||
|
||||
boost::mutex::scoped_lock l(m_send_buffer_mutex);
|
||||
#ifdef TORRENT_STATS
|
||||
m_buffer_allocations -= num_buffers;
|
||||
TORRENT_ASSERT(m_buffer_allocations >= 0);
|
||||
|
|
Loading…
Reference in New Issue