add additional single-thread asserts and separate torrents from the session (in preparation for running them in separate threads/strands)

This commit is contained in:
Arvid Norberg 2014-09-22 17:41:06 +00:00
parent a6eda97281
commit 7a55069ec9
5 changed files with 229 additions and 89 deletions

View File

@ -180,6 +180,9 @@ namespace libtorrent
void thread_started()
{ m_single_thread = pthread_self(); }
void transfer_ownership()
{ m_single_thread = 0; }
private:
mutable pthread_t m_single_thread;
};

View File

@ -1468,6 +1468,7 @@ namespace libtorrent
// this is true while there is an outstanding
// async write job on the socket
bool m_socket_is_writing;
bool is_single_thread() const;
#endif
};

View File

@ -78,6 +78,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/link.hpp"
#include "libtorrent/vector_utils.hpp"
#include "libtorrent/linked_list.hpp"
#include "libtorrent/debug.hpp"
#if TORRENT_COMPLETE_TYPES_REQUIRED
#include "libtorrent/peer_connection.hpp"
@ -233,7 +234,8 @@ namespace libtorrent
// for a specific download. It updates itself against
// the tracker
class TORRENT_EXTRA_EXPORT torrent
: public torrent_hot_members
: public single_threaded
, public torrent_hot_members
, public request_callback
, public peer_class_set
, public boost::enable_shared_from_this<torrent>
@ -276,6 +278,7 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS
bool has_peer(peer_connection const* p) const
{ return sorted_find(m_connections, (peer_connection*)p) != m_connections.end(); }
bool is_single_thread() const { return single_threaded::is_single_thread(); }
#endif
// this is called when the torrent has metadata.

View File

@ -124,6 +124,15 @@ namespace libtorrent
}
#endif
#if TORRENT_USE_ASSERTS
bool peer_connection::is_single_thread() const
{
boost::shared_ptr<torrent> t = m_torrent.lock();
if (!t) return true;
return t->is_single_thread();
}
#endif
// outbound connection
peer_connection::peer_connection(peer_connection_args const& pack)
: peer_connection_hot_members(pack.tor, *pack.ses, *pack.sett)
@ -262,6 +271,7 @@ namespace libtorrent
int peer_connection::timeout() const
{
TORRENT_ASSERT(is_single_thread());
int ret = m_settings.get_int(settings_pack::peer_timeout);
#if TORRENT_USE_I2P
if (m_peer_info && m_peer_info->is_i2p_addr)
@ -275,12 +285,14 @@ namespace libtorrent
void peer_connection::increase_est_reciprocation_rate()
{
TORRENT_ASSERT(is_single_thread());
m_est_reciprocation_rate += m_est_reciprocation_rate
* m_settings.get_int(settings_pack::increase_est_reciprocation_rate) / 100;
}
void peer_connection::decrease_est_reciprocation_rate()
{
TORRENT_ASSERT(is_single_thread());
m_est_reciprocation_rate -= m_est_reciprocation_rate
* m_settings.get_int(settings_pack::decrease_est_reciprocation_rate) / 100;
}
@ -288,6 +300,7 @@ namespace libtorrent
bool peer_connection::bittyrant_unchoke_compare(
peer_connection const* p) const
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p);
peer_connection const& rhs = *p;
@ -317,6 +330,7 @@ namespace libtorrent
// return true if 'this' peer should be preferred to be unchoke over p
bool peer_connection::unchoke_compare(peer_connection const* p) const
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p);
peer_connection const& rhs = *p;
@ -430,6 +444,7 @@ namespace libtorrent
int peer_connection::get_priority(int channel) const
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(channel >= 0 && channel < 2);
int prio = 1;
for (int i = 0; i < num_classes(); ++i)
@ -453,6 +468,7 @@ namespace libtorrent
bool peer_connection::upload_rate_compare(peer_connection const* p) const
{
TORRENT_ASSERT(is_single_thread());
size_type c1;
size_type c2;
@ -468,12 +484,14 @@ namespace libtorrent
void peer_connection::reset_choke_counters()
{
TORRENT_ASSERT(is_single_thread());
m_downloaded_at_last_round= m_statistics.total_payload_download();
m_uploaded_at_last_round = m_statistics.total_payload_upload();
}
void peer_connection::start()
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_peer_info == 0 || m_peer_info->connection == this);
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -534,6 +552,7 @@ namespace libtorrent
void peer_connection::update_interest()
{
TORRENT_ASSERT(is_single_thread());
if (!m_need_interest_update)
{
// we're the first to request an interest update
@ -549,6 +568,7 @@ namespace libtorrent
void peer_connection::do_update_interest()
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_need_interest_update);
m_need_interest_update = false;
@ -610,6 +630,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
void peer_connection::peer_log(char const* fmt, ...) const
{
TORRENT_ASSERT(is_single_thread());
if (!m_logger) return;
va_list v;
@ -627,11 +648,13 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
void peer_connection::add_extension(boost::shared_ptr<peer_plugin> ext)
{
TORRENT_ASSERT(is_single_thread());
m_extensions.push_back(ext);
}
peer_plugin const* peer_connection::find_plugin(char const* type)
{
TORRENT_ASSERT(is_single_thread());
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
@ -643,6 +666,7 @@ namespace libtorrent
void peer_connection::send_allowed_set()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -745,6 +769,7 @@ namespace libtorrent
void peer_connection::on_metadata_impl()
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = associated_torrent().lock();
m_have_piece.resize(t->torrent_file().num_pieces(), m_have_all);
m_num_pieces = m_have_piece.count();
@ -779,6 +804,7 @@ namespace libtorrent
void peer_connection::init()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -924,6 +950,7 @@ namespace libtorrent
int peer_connection::picker_options() const
{
TORRENT_ASSERT(is_single_thread());
int ret = m_picker_options;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -974,6 +1001,7 @@ namespace libtorrent
void peer_connection::fast_reconnect(bool r)
{
TORRENT_ASSERT(is_single_thread());
if (!peer_info_struct() || peer_info_struct()->fast_reconnects > 1)
return;
m_fast_reconnect = r;
@ -989,6 +1017,7 @@ namespace libtorrent
void peer_connection::received_piece(int index)
{
TORRENT_ASSERT(is_single_thread());
// dont announce during handshake
if (in_handshake()) return;
@ -1025,6 +1054,7 @@ namespace libtorrent
void peer_connection::announce_piece(int index)
{
TORRENT_ASSERT(is_single_thread());
// dont announce during handshake
if (in_handshake()) return;
@ -1055,6 +1085,7 @@ namespace libtorrent
bool peer_connection::has_piece(int i) const
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
TORRENT_ASSERT(t->valid_metadata());
@ -1065,21 +1096,25 @@ namespace libtorrent
std::vector<pending_block> const& peer_connection::request_queue() const
{
TORRENT_ASSERT(is_single_thread());
return m_request_queue;
}
std::vector<pending_block> const& peer_connection::download_queue() const
{
TORRENT_ASSERT(is_single_thread());
return m_download_queue;
}
std::vector<peer_request> const& peer_connection::upload_queue() const
{
TORRENT_ASSERT(is_single_thread());
return m_requests;
}
time_duration peer_connection::download_queue_time(int extra_bytes) const
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
@ -1123,11 +1158,13 @@ namespace libtorrent
void peer_connection::add_stat(size_type downloaded, size_type uploaded)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.add_stat(downloaded, uploaded);
}
void peer_connection::received_bytes(int bytes_payload, int bytes_protocol)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.received_bytes(bytes_payload, bytes_protocol);
if (m_ignore_stats) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1137,6 +1174,7 @@ namespace libtorrent
void peer_connection::sent_bytes(int bytes_payload, int bytes_protocol)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.sent_bytes(bytes_payload, bytes_protocol);
#ifndef TORRENT_DISABLE_EXTENSIONS
if (bytes_payload)
@ -1156,6 +1194,7 @@ namespace libtorrent
void peer_connection::trancieve_ip_packet(int bytes, bool ipv6)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.trancieve_ip_packet(bytes, ipv6);
if (m_ignore_stats) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1165,6 +1204,7 @@ namespace libtorrent
void peer_connection::sent_syn(bool ipv6)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.sent_syn(ipv6);
if (m_ignore_stats) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1174,6 +1214,7 @@ namespace libtorrent
void peer_connection::received_synack(bool ipv6)
{
TORRENT_ASSERT(is_single_thread());
m_statistics.received_synack(ipv6);
if (m_ignore_stats) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1183,11 +1224,13 @@ namespace libtorrent
bitfield const& peer_connection::get_bitfield() const
{
TORRENT_ASSERT(is_single_thread());
return m_have_piece;
}
void peer_connection::received_valid_data(int index)
{
TORRENT_ASSERT(is_single_thread());
// this fails because we haven't had time to disconnect
// seeds yet, and we might have just become one
// INVARIANT_CHECK;
@ -1205,6 +1248,7 @@ namespace libtorrent
bool peer_connection::received_invalid_data(int index, bool single_peer)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -1223,6 +1267,7 @@ namespace libtorrent
// and if it can correspond to a request generated by libtorrent.
bool peer_connection::verify_piece(const peer_request& p) const
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
@ -1238,6 +1283,7 @@ namespace libtorrent
void peer_connection::attach_to_torrent(sha1_hash const& ih, bool allow_encrypted)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -1381,6 +1427,7 @@ namespace libtorrent
boost::uint32_t peer_connection::peer_rank() const
{
TORRENT_ASSERT(is_single_thread());
return m_peer_info == NULL ? 0
: m_peer_info->rank(m_ses.external_address(), m_ses.listen_port());
}
@ -1393,6 +1440,7 @@ namespace libtorrent
void peer_connection::incoming_keepalive()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING
@ -1406,6 +1454,7 @@ namespace libtorrent
void peer_connection::set_endgame(bool b)
{
TORRENT_ASSERT(is_single_thread());
if (m_endgame_mode == b) return;
m_endgame_mode = b;
if (m_endgame_mode)
@ -1416,6 +1465,7 @@ namespace libtorrent
void peer_connection::incoming_choke()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -1441,6 +1491,7 @@ namespace libtorrent
void peer_connection::clear_request_queue()
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
if (!t->has_picker())
@ -1479,6 +1530,7 @@ namespace libtorrent
void peer_connection::incoming_reject_request(peer_request const& r)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1570,6 +1622,7 @@ namespace libtorrent
void peer_connection::incoming_suggest(int index)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING
@ -1628,6 +1681,7 @@ namespace libtorrent
void peer_connection::incoming_unchoke()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1670,6 +1724,7 @@ namespace libtorrent
void peer_connection::incoming_interested()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1728,6 +1783,7 @@ namespace libtorrent
void peer_connection::maybe_unchoke_this_peer()
{
TORRENT_ASSERT(is_single_thread());
if (ignore_unchoke_slots())
{
#ifdef TORRENT_VERBOSE_LOGGING
@ -1773,6 +1829,7 @@ namespace libtorrent
void peer_connection::incoming_not_interested()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -1809,6 +1866,7 @@ namespace libtorrent
void peer_connection::choke_this_peer()
{
TORRENT_ASSERT(is_single_thread());
if (is_choked()) return;
if (ignore_unchoke_slots())
{
@ -1835,6 +1893,7 @@ namespace libtorrent
void peer_connection::incoming_have(int index)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -1990,6 +2049,7 @@ namespace libtorrent
void peer_connection::incoming_dont_have(int index)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -2047,6 +2107,7 @@ namespace libtorrent
void peer_connection::incoming_bitfield(bitfield const& bits)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -2178,6 +2239,7 @@ namespace libtorrent
bool peer_connection::disconnect_if_redundant()
{
TORRENT_ASSERT(is_single_thread());
if (m_disconnecting) return false;
// we cannot disconnect in a constructor
@ -2218,6 +2280,7 @@ namespace libtorrent
bool peer_connection::can_disconnect(error_code const& ec) const
{
TORRENT_ASSERT(is_single_thread());
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::const_iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
@ -2234,6 +2297,7 @@ namespace libtorrent
void peer_connection::incoming_request(peer_request const& r)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -2435,6 +2499,7 @@ namespace libtorrent
// reject all requests to this piece
void peer_connection::reject_piece(int index)
{
TORRENT_ASSERT(is_single_thread());
for (std::vector<peer_request>::iterator i = m_requests.begin()
, end(m_requests.end()); i != end; ++i)
{
@ -2450,6 +2515,7 @@ namespace libtorrent
void peer_connection::incoming_piece_fragment(int bytes)
{
TORRENT_ASSERT(is_single_thread());
m_last_piece = time_now();
TORRENT_ASSERT(m_outstanding_bytes >= bytes);
m_outstanding_bytes -= bytes;
@ -2470,6 +2536,7 @@ namespace libtorrent
void peer_connection::start_receive_piece(peer_request const& r)
{
TORRENT_ASSERT(is_single_thread());
#if TORRENT_USE_INVARIANT_CHECKS
check_invariant();
#endif
@ -2593,6 +2660,7 @@ namespace libtorrent
void peer_connection::incoming_piece(peer_request const& p, char const* data)
{
TORRENT_ASSERT(is_single_thread());
bool exceeded = false;
char* buffer = m_allocator.allocate_disk_buffer(exceeded, self(), "receive buffer");
@ -2619,6 +2687,7 @@ namespace libtorrent
void peer_connection::incoming_piece(peer_request const& p, disk_buffer_holder& data)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -2930,6 +2999,7 @@ namespace libtorrent
void peer_connection::on_disk_write_complete(disk_io_job const* j
, peer_request p, boost::shared_ptr<torrent> t)
{
TORRENT_ASSERT(is_single_thread());
torrent_ref_holder h(t.get(), "async_write");
if (t) t->dec_refcount("async_write");
@ -3026,6 +3096,7 @@ namespace libtorrent
void peer_connection::incoming_cancel(peer_request const& r)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -3077,6 +3148,7 @@ namespace libtorrent
void peer_connection::incoming_dht_port(int listen_port)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING
@ -3094,6 +3166,7 @@ namespace libtorrent
void peer_connection::incoming_have_all()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3176,6 +3249,7 @@ namespace libtorrent
void peer_connection::incoming_have_none()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING
@ -3223,6 +3297,7 @@ namespace libtorrent
void peer_connection::incoming_allowed_fast(int index)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3292,6 +3367,7 @@ namespace libtorrent
std::vector<int> const& peer_connection::allowed_fast()
{
TORRENT_ASSERT(is_single_thread());
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
@ -3301,6 +3377,7 @@ namespace libtorrent
bool peer_connection::can_request_time_critical() const
{
TORRENT_ASSERT(is_single_thread());
if (has_peer_choked() || !is_interesting()) return false;
if ((int)m_download_queue.size() + (int)m_request_queue.size()
> m_desired_queue_size * 2) return false;
@ -3318,6 +3395,7 @@ namespace libtorrent
bool peer_connection::make_time_critical(piece_block const& block)
{
TORRENT_ASSERT(is_single_thread());
std::vector<pending_block>::iterator rit = std::find_if(m_request_queue.begin()
, m_request_queue.end(), has_block(block));
if (rit == m_request_queue.end()) return false;
@ -3338,6 +3416,7 @@ namespace libtorrent
bool peer_connection::add_request(piece_block const& block, int flags)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3460,6 +3539,7 @@ namespace libtorrent
void peer_connection::cancel_all_requests()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3514,6 +3594,7 @@ namespace libtorrent
void peer_connection::cancel_request(piece_block const& block, bool force)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3580,6 +3661,7 @@ namespace libtorrent
bool peer_connection::send_choke()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_choked)
@ -3635,6 +3717,7 @@ namespace libtorrent
bool peer_connection::send_unchoke()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (!m_choked) return false;
@ -3676,6 +3759,7 @@ namespace libtorrent
void peer_connection::send_interested()
{
TORRENT_ASSERT(is_single_thread());
if (m_interesting) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
if (!t->ready_for_connections()) return;
@ -3690,6 +3774,7 @@ namespace libtorrent
void peer_connection::send_not_interested()
{
TORRENT_ASSERT(is_single_thread());
// we cannot disconnect in a constructor, and
// this function may end up doing that
TORRENT_ASSERT(m_in_constructor == false);
@ -3719,6 +3804,7 @@ namespace libtorrent
void peer_connection::send_suggest(int piece)
{
TORRENT_ASSERT(is_single_thread());
if (m_connecting) return;
if (in_handshake()) return;
@ -3752,6 +3838,7 @@ namespace libtorrent
void peer_connection::send_block_requests()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -3921,6 +4008,7 @@ namespace libtorrent
void peer_connection::on_connect_timeout()
{
TORRENT_ASSERT(is_single_thread());
m_queued_for_connection = false;
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -3935,6 +4023,7 @@ namespace libtorrent
void peer_connection::connect_failed(error_code const& e)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(e);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
@ -4006,6 +4095,7 @@ namespace libtorrent
// 2 protocol error (client sent something invalid)
void peer_connection::disconnect(error_code const& ec, operation_t op, int error)
{
TORRENT_ASSERT(is_single_thread());
#if TORRENT_USE_ASSERTS
m_disconnect_started = true;
#endif
@ -4250,6 +4340,7 @@ namespace libtorrent
bool peer_connection::ignore_unchoke_slots() const
{
TORRENT_ASSERT(is_single_thread());
if (num_classes() == 0) return true;
if (m_ses.ignore_unchoke_slots_set(*this)) return true;
@ -4263,6 +4354,7 @@ namespace libtorrent
bool peer_connection::on_local_network() const
{
TORRENT_ASSERT(is_single_thread());
if (libtorrent::is_local(m_remote.address())
|| is_loopback(m_remote.address())) return true;
return false;
@ -4270,6 +4362,7 @@ namespace libtorrent
void peer_connection::get_peer_info(peer_info& p) const
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(!associated_torrent().expired());
ptime now = time_now();
@ -4414,6 +4507,7 @@ namespace libtorrent
// to the caller
bool peer_connection::allocate_disk_receive_buffer(int disk_buffer_size)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(m_packet_size > 0);
@ -4459,6 +4553,7 @@ namespace libtorrent
char* peer_connection::release_disk_receive_buffer()
{
TORRENT_ASSERT(is_single_thread());
if (!m_disk_recv_buffer) return 0;
TORRENT_ASSERT(m_disk_recv_buffer_size <= m_recv_end);
@ -4473,6 +4568,7 @@ namespace libtorrent
// offset = the offset into the receive buffer where to remove `size` bytes
void peer_connection::cut_receive_buffer(int size, int packet_size, int offset)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(packet_size > 0);
@ -4514,6 +4610,7 @@ namespace libtorrent
// in the receive buffer that have been parsed and processed.
void peer_connection::normalize_receive_buffer()
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_recv_end >= m_recv_start);
if (m_recv_start == 0) return;
@ -4530,6 +4627,7 @@ namespace libtorrent
void peer_connection::superseed_piece(int replace_piece, int new_piece)
{
TORRENT_ASSERT(is_single_thread());
if (new_piece == -1)
{
if (m_superseed_piece[0] == -1) return;
@ -4570,6 +4668,7 @@ namespace libtorrent
void peer_connection::update_desired_queue_size()
{
TORRENT_ASSERT(is_single_thread());
if (m_snubbed)
{
m_desired_queue_size = 1;
@ -4601,6 +4700,7 @@ namespace libtorrent
void peer_connection::second_tick(int tick_interval_ms)
{
TORRENT_ASSERT(is_single_thread());
ptime now = time_now();
boost::shared_ptr<peer_connection> me(self());
@ -4843,6 +4943,7 @@ namespace libtorrent
void peer_connection::snub_peer()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -4936,6 +5037,7 @@ namespace libtorrent
int peer_connection::preferred_caching() const
{
TORRENT_ASSERT(is_single_thread());
int line_size = 0;
if (m_settings.get_bool(settings_pack::guided_read_cache))
{
@ -4960,6 +5062,7 @@ namespace libtorrent
void peer_connection::fill_send_buffer()
{
TORRENT_ASSERT(is_single_thread());
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
@ -5084,6 +5187,7 @@ namespace libtorrent
// checked, while in seed-mode
void peer_connection::on_seed_mode_hashed(disk_io_job const* j)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -5137,6 +5241,7 @@ namespace libtorrent
void peer_connection::on_disk_read_complete(disk_io_job const* j
, peer_request r, ptime issue_time)
{
TORRENT_ASSERT(is_single_thread());
// return value:
// 0: success, piece passed hash check
// -1: disk failure
@ -5229,6 +5334,7 @@ namespace libtorrent
void peer_connection::assign_bandwidth(int channel, int amount)
{
TORRENT_ASSERT(is_single_thread());
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("%s ASSIGN BANDWIDHT [ bytes: %d ]"
, channel == upload_channel ? ">>>" : "<<<", amount);
@ -5259,6 +5365,7 @@ namespace libtorrent
// by the rate limiter to allocate quota for this peer
int peer_connection::wanted_transfer(int channel)
{
TORRENT_ASSERT(is_single_thread());
shared_ptr<torrent> t = m_torrent.lock();
if (channel == download_channel)
@ -5279,6 +5386,7 @@ namespace libtorrent
int peer_connection::request_bandwidth(int channel, int bytes)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
// we can only have one outstanding bandwidth request at a time
if (m_channel_state[channel] & peer_info::bw_limit) return 0;
@ -5349,6 +5457,7 @@ namespace libtorrent
void peer_connection::uncork_socket()
{
TORRENT_ASSERT(is_single_thread());
if (!m_corked) return;
m_corked = false;
setup_send();
@ -5356,6 +5465,7 @@ namespace libtorrent
void peer_connection::setup_send()
{
TORRENT_ASSERT(is_single_thread());
if (m_disconnecting) return;
// we may want to request more quota at this point
@ -5485,6 +5595,7 @@ namespace libtorrent
void peer_connection::on_disk()
{
TORRENT_ASSERT(is_single_thread());
if ((m_channel_state[download_channel] & peer_info::bw_disk) == 0) return;
boost::shared_ptr<peer_connection> me(self());
@ -5498,6 +5609,7 @@ namespace libtorrent
void peer_connection::on_allocate_disk_buffer(char* buffer, int buffer_size)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(!m_disk_recv_buffer);
@ -5514,6 +5626,7 @@ namespace libtorrent
void peer_connection::setup_receive(sync_t sync)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_disconnecting) return;
@ -5551,6 +5664,7 @@ namespace libtorrent
size_t peer_connection::try_read(sync_t s, error_code& ec)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_connected);
if (m_quota[download_channel] == 0)
@ -5718,6 +5832,7 @@ namespace libtorrent
// returns the last 'bytes' from the receive buffer
std::pair<buffer::interval, buffer::interval> peer_connection::wr_recv_buffers(int bytes)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(bytes <= m_recv_pos);
std::pair<buffer::interval, buffer::interval> vec;
@ -5752,6 +5867,7 @@ namespace libtorrent
void peer_connection::reset_recv_buffer(int packet_size)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_recv_buffer.size() >= m_recv_end);
TORRENT_ASSERT(packet_size > 0);
if (m_recv_end > m_packet_size)
@ -5770,6 +5886,7 @@ namespace libtorrent
, chained_buffer::free_buffer_fun destructor, void* userdata
, block_cache_reference ref, bool encrypted)
{
TORRENT_ASSERT(is_single_thread());
// bittorrent connections should never use this function, since
// they might be encrypted and this would circumvent the actual
// encryption. bt_peer_connection overrides this function with
@ -5783,6 +5900,7 @@ namespace libtorrent
, chained_buffer::free_buffer_fun destructor, void* userdata
, block_cache_reference ref)
{
TORRENT_ASSERT(is_single_thread());
m_send_buffer.append_buffer((char*)buffer, size, size, destructor
, userdata, ref);
}
@ -5796,6 +5914,7 @@ namespace libtorrent
void peer_connection::send_buffer(char const* buf, int size, int flags
, void (*fun)(char*, int, void*), void* userdata)
{
TORRENT_ASSERT(is_single_thread());
int free_space = m_send_buffer.space_in_last_buffer();
if (free_space > size) free_space = size;
if (free_space > 0)
@ -5845,6 +5964,7 @@ namespace libtorrent
void peer_connection::on_receive_data_nb(const error_code& error
, std::size_t bytes_transferred)
{
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_ASIO_DEBUGGING
complete_async("peer_connection::on_receive_data_nb");
#endif
@ -5955,6 +6075,7 @@ namespace libtorrent
void peer_connection::on_receive_data(const error_code& error
, std::size_t bytes_transferred)
{
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_ASIO_DEBUGGING
complete_async("peer_connection::on_receive_data");
#endif
@ -5970,6 +6091,7 @@ namespace libtorrent
void peer_connection::receive_data_impl(const error_code& error
, std::size_t bytes_transferred, int read_loops)
{
TORRENT_ASSERT(is_single_thread());
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]"
, bytes_transferred, error.message().c_str());
@ -6116,6 +6238,7 @@ namespace libtorrent
bool peer_connection::can_write() const
{
TORRENT_ASSERT(is_single_thread());
// if we have requests or pending data to be sent or announcements to be made
// we want to send data
return !m_send_buffer.empty()
@ -6125,6 +6248,7 @@ namespace libtorrent
bool peer_connection::can_read()
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -6169,6 +6293,7 @@ namespace libtorrent
void peer_connection::on_allow_connect(int ticket)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_queued_for_connection);
m_queued_for_connection = false;
@ -6263,6 +6388,7 @@ namespace libtorrent
void peer_connection::on_connection_complete(error_code const& e)
{
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_ASIO_DEBUGGING
complete_async("peer_connection::on_connection_complete");
#endif
@ -6418,6 +6544,7 @@ namespace libtorrent
void peer_connection::on_send_data(error_code const& error
, std::size_t bytes_transferred)
{
TORRENT_ASSERT(is_single_thread());
m_counters.inc_stats_counter(counters::on_write_counter);
m_ses.sent_buffer(bytes_transferred);
@ -6524,6 +6651,7 @@ namespace libtorrent
void peer_connection::check_invariant() const
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_in_use == 1337);
TORRENT_ASSERT(m_queued_time_critical <= int(m_request_queue.size()));
TORRENT_ASSERT(m_recv_end >= m_recv_start);
@ -6766,6 +6894,7 @@ namespace libtorrent
peer_connection::peer_speed_t peer_connection::peer_speed()
{
TORRENT_ASSERT(is_single_thread());
shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
@ -6786,6 +6915,7 @@ namespace libtorrent
void peer_connection::keep_alive()
{
TORRENT_ASSERT(is_single_thread());
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
INVARIANT_CHECK;
#endif
@ -6811,6 +6941,7 @@ namespace libtorrent
bool peer_connection::is_seed() const
{
TORRENT_ASSERT(is_single_thread());
// if m_num_pieces == 0, we probably don't have the
// metadata yet.
boost::shared_ptr<torrent> t = m_torrent.lock();
@ -6819,6 +6950,7 @@ namespace libtorrent
void peer_connection::set_share_mode(bool u)
{
TORRENT_ASSERT(is_single_thread());
// if the peer is a seed, ignore share mode messages
if (is_seed()) return;
@ -6827,6 +6959,7 @@ namespace libtorrent
void peer_connection::set_upload_only(bool u)
{
TORRENT_ASSERT(is_single_thread());
// if the peer is a seed, don't allow setting
// upload_only to false
if (m_upload_only || is_seed()) return;

View File

@ -301,7 +301,7 @@ namespace libtorrent
if (!m_url.empty() && m_uuid.empty()) m_uuid = m_url;
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
debug_log("creating torrent: %s", torrent_file().name().c_str());
#endif
@ -735,7 +735,7 @@ namespace libtorrent
void torrent::start()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
debug_log("starting torrent");
#endif
@ -823,7 +823,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_DHT
bool torrent::should_announce_dht() const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!m_ses.announce_dht()) return false;
if (!m_ses.dht()) return false;
@ -1054,7 +1054,7 @@ namespace libtorrent
void torrent::handle_disk_error(disk_io_job const* j, peer_connection* c)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!j->error) return;
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -1183,7 +1183,7 @@ namespace libtorrent
torrent_ref_holder h(this, "read_piece");
dec_refcount("read_piece");
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
disk_buffer_holder buffer(m_ses, *j);
@ -1242,7 +1242,7 @@ namespace libtorrent
void torrent::add_piece(int piece, char const* data, int flags)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(piece >= 0 && piece < m_torrent_file->num_pieces());
int piece_size = m_torrent_file->piece_size(piece);
int blocks_in_piece = (piece_size + block_size() - 1) / block_size();
@ -1312,7 +1312,7 @@ namespace libtorrent
torrent_ref_holder h(this, "add_piece");
dec_refcount("add_piece");
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
schedule_storage_tick();
@ -1691,7 +1691,7 @@ namespace libtorrent
// shared_from_this()
void torrent::init()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!need_loaded()) return;
TORRENT_ASSERT(m_torrent_file->num_files() > 0);
@ -1932,7 +1932,7 @@ namespace libtorrent
void torrent::dec_refcount(char const* purpose)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_refcount > 0);
--m_refcount;
if (m_refcount == 0)
@ -1947,7 +1947,7 @@ namespace libtorrent
void torrent::inc_refcount(char const* purpose)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(is_loaded());
++m_refcount;
if (!m_pinned && m_refcount == 1)
@ -1956,7 +1956,7 @@ namespace libtorrent
void torrent::set_pinned(bool p)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_pinned == p) return;
m_pinned = p;
@ -2104,7 +2104,7 @@ namespace libtorrent
bool need_save_resume_data = m_need_save_resume_data;
dec_refcount("check_fastresume");
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (j->ret == piece_manager::fatal_disk_error)
{
@ -2417,7 +2417,7 @@ namespace libtorrent
void torrent::on_force_recheck(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
// hold a reference until this function returns
torrent_ref_holder h(this, "force_recheck");
@ -2498,7 +2498,7 @@ namespace libtorrent
// hold a reference until this function returns
torrent_ref_holder h(this, "start_checking");
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
dec_refcount("start_checking");
@ -2674,7 +2674,7 @@ namespace libtorrent
void torrent::on_tracker_announce()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
m_waiting_tracker = false;
if (m_abort) return;
announce_with_tracker();
@ -2723,7 +2723,7 @@ namespace libtorrent
void torrent::dht_announce()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!m_ses.dht())
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -2804,7 +2804,7 @@ namespace libtorrent
void torrent::on_dht_announce_response(std::vector<tcp::endpoint> const& peers)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
debug_log("END DHT announce (%d ms) (%d peers)"
@ -2836,7 +2836,7 @@ namespace libtorrent
void torrent::announce_with_tracker(boost::uint8_t e
, address const& bind_interface)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_trackers.empty())
@ -3034,7 +3034,7 @@ namespace libtorrent
void torrent::scrape_tracker()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
m_last_scrape = m_ses.session_time();
if (m_trackers.empty()) return;
@ -3053,7 +3053,7 @@ namespace libtorrent
void torrent::tracker_warning(tracker_request const& req, std::string const& msg)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -3064,7 +3064,7 @@ namespace libtorrent
void torrent::tracker_scrape_response(tracker_request const& req
, int complete, int incomplete, int downloaded, int downloaders)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(req.kind == tracker_request::scrape_request);
@ -3127,7 +3127,7 @@ namespace libtorrent
, address const& external_ip
, const std::string& trackerid)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(r.kind == tracker_request::announce_request);
@ -3400,7 +3400,7 @@ namespace libtorrent
#if TORRENT_USE_I2P
void torrent::on_i2p_resolve(error_code const& ec, char const* dest)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -3421,7 +3421,7 @@ namespace libtorrent
void torrent::on_peer_name_lookup(error_code const& e
, std::vector<address> const& host_list, int port)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -3771,7 +3771,7 @@ namespace libtorrent
void torrent::on_piece_verified(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
torrent_ref_holder h(this, "verify_piece");
@ -3874,7 +3874,7 @@ namespace libtorrent
// is correct
void torrent::we_have(int index)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(!has_picker() || m_picker->has_piece_passed(index));
inc_stats_counter(counters::num_have_pieces);
@ -4039,7 +4039,7 @@ namespace libtorrent
void torrent::piece_passed(int index)
{
// INVARIANT_CHECK;
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(!m_picker->has_piece_passed(index));
#if defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -4135,7 +4135,7 @@ namespace libtorrent
// invariant check here since it assumes:
// (total_done == m_torrent_file->total_size()) => is_seed()
INVARIANT_CHECK;
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_picker.get());
TORRENT_ASSERT(index >= 0);
@ -4603,7 +4603,7 @@ namespace libtorrent
void torrent::abort()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_abort) return;
@ -4733,7 +4733,7 @@ namespace libtorrent
void torrent::on_files_deleted(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
dec_refcount("delete_files");
if (j->ret != 0)
@ -4750,7 +4750,7 @@ namespace libtorrent
void torrent::on_save_resume_data(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
torrent_ref_holder h(this, "save_resume");
dec_refcount("save_resume");
m_ses.done_async_resume();
@ -4772,7 +4772,7 @@ namespace libtorrent
void torrent::on_file_renamed(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
dec_refcount("rename_file");
if (j->ret == 0)
@ -4791,7 +4791,7 @@ namespace libtorrent
void torrent::on_torrent_paused(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (alerts().should_post<torrent_paused_alert>())
alerts().post_alert(torrent_paused_alert(get_handle()));
@ -5740,7 +5740,7 @@ namespace libtorrent
INVARIANT_CHECK;
TORRENT_ASSERT(p != 0);
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
peer_iterator i = sorted_find(m_connections, p);
if (i == m_connections.end())
@ -5827,7 +5827,7 @@ namespace libtorrent
void torrent::connect_to_url_seed(std::list<web_seed_entry>::iterator web)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(!web->resolving);
@ -5980,7 +5980,7 @@ namespace libtorrent
void torrent::on_proxy_name_lookup(error_code const& e, tcp::resolver::iterator host
, std::list<web_seed_entry>::iterator web)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -6065,7 +6065,7 @@ namespace libtorrent
void torrent::on_name_lookup(error_code const& e, tcp::resolver::iterator host
, std::list<web_seed_entry>::iterator web, tcp::endpoint proxy)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -6113,7 +6113,7 @@ namespace libtorrent
void torrent::connect_web_seed(std::list<web_seed_entry>::iterator web, tcp::endpoint a)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_abort) return;
if (m_apply_ip_filter
@ -6304,7 +6304,7 @@ namespace libtorrent
void torrent::resolve_peer_country(boost::shared_ptr<peer_connection> const& p) const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_resolving_country
|| is_local(p->remote().address())
|| p->has_country()
@ -6339,7 +6339,7 @@ namespace libtorrent
, std::vector<address> const& host_list
, boost::shared_ptr<peer_connection> p) const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -7013,7 +7013,7 @@ namespace libtorrent
void torrent::get_download_queue(std::vector<partial_piece_info>* queue)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
queue->clear();
std::vector<block_info>& blk = m_ses.block_info_storage();
blk.clear();
@ -7103,7 +7103,7 @@ namespace libtorrent
bool torrent::connect_to_peer(torrent_peer* peerinfo, bool ignore_limit)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(peerinfo);
@ -7301,7 +7301,7 @@ namespace libtorrent
bool torrent::set_metadata(char const* metadata_buf, int metadata_size)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_torrent_file->is_valid()) return false;
@ -8014,7 +8014,7 @@ namespace libtorrent
void torrent::files_checked()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_torrent_file->is_valid());
if (m_abort)
@ -8131,7 +8131,7 @@ namespace libtorrent
alert_manager& torrent::alerts() const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
return m_ses.alerts();
}
@ -8158,7 +8158,7 @@ namespace libtorrent
void torrent::move_storage(std::string const& save_path, int flags)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_abort)
@ -8201,7 +8201,7 @@ namespace libtorrent
void torrent::on_storage_moved(disk_io_job const* j)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
m_moving_storage = false;
dec_refcount("move_storage");
@ -8231,13 +8231,13 @@ namespace libtorrent
torrent_handle torrent::get_handle()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
return torrent_handle(shared_from_this());
}
aux::session_settings const& torrent::settings() const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
return m_ses.settings();
}
@ -8292,7 +8292,7 @@ namespace libtorrent
TORRENT_ASSERT(want_tick() == m_links[aux::session_interface::torrent_want_tick].in_list());
TORRENT_ASSERT((!m_allow_peers && m_auto_managed) == m_links[aux::session_interface::torrent_want_scrape].in_list());
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
// this fires during disconnecting peers
// if (is_paused()) TORRENT_ASSERT(num_peers() == 0 || m_graceful_pause_mode);
@ -8450,7 +8450,7 @@ namespace libtorrent
void torrent::set_sequential_download(bool sd)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_sequential_download == sd) return;
m_sequential_download = sd;
@ -8472,7 +8472,7 @@ namespace libtorrent
void torrent::set_queue_position(int p)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT((p == -1) == is_finished()
|| (!m_auto_managed && p == -1)
|| (m_abort && p == -1));
@ -8488,7 +8488,7 @@ namespace libtorrent
void torrent::set_max_uploads(int limit, bool state_update)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(limit >= -1);
if (limit <= 0) limit = (1<<24)-1;
if (m_max_uploads != limit && state_update) state_updated();
@ -8500,7 +8500,7 @@ namespace libtorrent
void torrent::set_max_connections(int limit, bool state_update)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(limit >= -1);
if (limit <= 0) limit = (1<<24)-1;
if (m_max_connections != limit && state_update) state_updated();
@ -8531,7 +8531,7 @@ namespace libtorrent
void torrent::set_limit_impl(int limit, int channel, bool state_update)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(limit >= -1);
if (limit <= 0) limit = 0;
@ -8556,7 +8556,7 @@ namespace libtorrent
int torrent::limit_impl(int channel) const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_peer_class == 0) return -1;
int limit = m_ses.peer_classes().at(m_peer_class)->channel[channel].throttle();
@ -8576,7 +8576,7 @@ namespace libtorrent
bool torrent::delete_files()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING
log_to_all_peers("DELETING FILES IN TORRENT");
@ -8600,7 +8600,7 @@ namespace libtorrent
void torrent::clear_error()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!m_error) return;
bool checking_files = should_check_files();
m_ses.trigger_auto_manage();
@ -8641,7 +8641,7 @@ namespace libtorrent
void torrent::set_error(error_code const& ec, int error_file)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
m_error = ec;
m_error_file = error_file;
@ -8665,7 +8665,7 @@ namespace libtorrent
void torrent::auto_managed(bool a)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_auto_managed == a) return;
@ -8746,7 +8746,7 @@ namespace libtorrent
// the higher seed rank, the more important to seed
int torrent::seed_rank(aux::session_settings const& s) const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
enum flags
{
seed_ratio_not_met = 0x40000000,
@ -8811,7 +8811,7 @@ namespace libtorrent
// just to save an empty resume data file
void torrent::save_resume_data(int flags)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (!valid_metadata())
@ -8886,7 +8886,7 @@ namespace libtorrent
bool torrent::should_check_files() const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
// #error should m_allow_peers really affect checking?
return m_state == torrent_status::checking_files
&& m_allow_peers
@ -8898,7 +8898,7 @@ namespace libtorrent
void torrent::flush_cache()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
// storage may be NULL during shutdown
if (!m_storage)
@ -8914,7 +8914,7 @@ namespace libtorrent
void torrent::on_cache_flushed(disk_io_job const* j)
{
dec_refcount("release_files");
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_ses.is_aborted()) return;
@ -8929,7 +8929,7 @@ namespace libtorrent
void torrent::pause(bool graceful)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (!m_allow_peers) return;
@ -8962,7 +8962,7 @@ namespace libtorrent
void torrent::do_pause()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!is_paused()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -9082,7 +9082,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING
void torrent::log_to_all_peers(char const* message)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
for (peer_iterator i = m_connections.begin();
i != m_connections.end(); ++i)
@ -9118,7 +9118,7 @@ namespace libtorrent
void torrent::set_allow_peers(bool b, bool graceful)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (m_allow_peers == b
&& m_graceful_pause_mode == graceful) return;
@ -9145,7 +9145,7 @@ namespace libtorrent
void torrent::resume()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
if (m_allow_peers
@ -9171,7 +9171,7 @@ namespace libtorrent
void torrent::do_resume()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (is_paused()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -9205,7 +9205,7 @@ namespace libtorrent
void torrent::update_tracker_timer(ptime now)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!m_announcing)
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
@ -9286,7 +9286,7 @@ namespace libtorrent
void torrent::start_announcing()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (is_paused())
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
@ -9346,7 +9346,7 @@ namespace libtorrent
void torrent::stop_announcing()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!m_announcing) return;
error_code ec;
@ -9385,7 +9385,7 @@ namespace libtorrent
void torrent::second_tick(int tick_interval_ms, int /* residual */)
{
TORRENT_ASSERT(want_tick());
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
boost::weak_ptr<torrent> self(shared_from_this());
@ -9790,7 +9790,7 @@ namespace libtorrent
void torrent::refresh_explicit_cache(int cache_size)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!ready_for_connections()) return;
if (m_abort) return;
@ -10268,7 +10268,7 @@ namespace libtorrent
void torrent::request_time_critical_pieces()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(!upload_mode());
// build a list of peers and sort it by download_queue_time
@ -10442,7 +10442,7 @@ namespace libtorrent
std::set<std::string> torrent::web_seeds(web_seed_entry::type_t type) const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
std::set<std::string> ret;
for (std::list<web_seed_entry>::const_iterator i = m_web_seeds.begin()
, end(m_web_seeds.end()); i != end; ++i)
@ -10496,7 +10496,7 @@ namespace libtorrent
void torrent::retry_web_seed(peer_connection* p, int retry)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
std::list<web_seed_entry>::iterator i = std::find_if(m_web_seeds.begin(), m_web_seeds.end()
, (boost::bind(&torrent_peer::connection, boost::bind(&web_seed_entry::peer_info, _1)) == p));
@ -10525,7 +10525,7 @@ namespace libtorrent
bool torrent::try_connect_peer()
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(want_peers());
torrent_state st = get_policy_state();
@ -10553,7 +10553,7 @@ namespace libtorrent
torrent_peer* torrent::add_peer(tcp::endpoint const& adr, int source, int flags)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
#if !TORRENT_USE_IPV6
if (!adr.address().is_v4()) return NULL;
@ -10762,7 +10762,7 @@ namespace libtorrent
#if !TORRENT_NO_FPU
void torrent::file_progress(std::vector<float>& fp)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!valid_metadata())
{
fp.clear();
@ -10786,7 +10786,7 @@ namespace libtorrent
void torrent::file_progress(std::vector<size_type>& fp, int flags)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
if (!valid_metadata())
{
fp.clear();
@ -10972,7 +10972,7 @@ namespace libtorrent
void torrent::set_state(torrent_status::state_t s)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(s != 0); // this state isn't used anymore
#if TORRENT_USE_ASSERTS
@ -11303,7 +11303,7 @@ namespace libtorrent
void torrent::add_redundant_bytes(int b, torrent::wasted_reason_t reason)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(b > 0);
m_total_redundant_bytes += b;
@ -11316,7 +11316,7 @@ namespace libtorrent
void torrent::add_failed_bytes(int b)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(b > 0);
m_total_failed_bytes += b;
m_stats_counters.inc_stats_counter(counters::recv_failed_bytes, b);
@ -11324,7 +11324,7 @@ namespace libtorrent
int torrent::num_seeds() const
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
int ret = 0;
@ -11338,7 +11338,7 @@ namespace libtorrent
, int response_code, error_code const& ec, const std::string& msg
, int retry_interval)
{
TORRENT_ASSERT(m_ses.is_single_thread());
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;