lt bandwidth limiter mutex fix
This commit is contained in:
parent
c7f3323d3e
commit
8f675ebacf
|
@ -124,6 +124,12 @@ struct bandwidth_manager
|
||||||
bool is_in_history(PeerConnection const* peer) const
|
bool is_in_history(PeerConnection const* peer) const
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
return is_in_history(peer, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_in_history(PeerConnection const* peer, boost::mutex::scoped_lock& l) const
|
||||||
|
{
|
||||||
|
TORRENT_ASSERT(l.locked());
|
||||||
for (typename history_t::const_iterator i
|
for (typename history_t::const_iterator i
|
||||||
= m_history.begin(), end(m_history.end()); i != end; ++i)
|
= m_history.begin(), end(m_history.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -140,10 +146,10 @@ struct bandwidth_manager
|
||||||
, int blk
|
, int blk
|
||||||
, bool non_prioritized) throw()
|
, bool non_prioritized) throw()
|
||||||
{
|
{
|
||||||
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
TORRENT_ASSERT(blk > 0);
|
TORRENT_ASSERT(blk > 0);
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
|
||||||
TORRENT_ASSERT(!peer->ignore_bandwidth_limits());
|
TORRENT_ASSERT(!peer->ignore_bandwidth_limits());
|
||||||
|
|
||||||
// make sure this peer isn't already in line
|
// make sure this peer isn't already in line
|
||||||
|
@ -235,13 +241,12 @@ private:
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
try {
|
try {
|
||||||
#endif
|
#endif
|
||||||
INVARIANT_CHECK;
|
|
||||||
|
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
|
||||||
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
INVARIANT_CHECK;
|
||||||
TORRENT_ASSERT(!m_history.empty());
|
TORRENT_ASSERT(!m_history.empty());
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
|
||||||
ptime now(time_now());
|
ptime now(time_now());
|
||||||
while (!m_history.empty() && m_history.back().expires_at <= now)
|
while (!m_history.empty() && m_history.back().expires_at <= now)
|
||||||
{
|
{
|
||||||
|
@ -279,6 +284,7 @@ private:
|
||||||
|
|
||||||
void hand_out_bandwidth(boost::mutex::scoped_lock& l) throw()
|
void hand_out_bandwidth(boost::mutex::scoped_lock& l) throw()
|
||||||
{
|
{
|
||||||
|
TORRENT_ASSERT(l.locked());
|
||||||
// if we're already handing out bandwidth, just return back
|
// if we're already handing out bandwidth, just return back
|
||||||
// to the loop further down on the callstack
|
// to the loop further down on the callstack
|
||||||
if (m_in_hand_out_bandwidth) return;
|
if (m_in_hand_out_bandwidth) return;
|
||||||
|
@ -313,7 +319,6 @@ private:
|
||||||
m_queue.swap(q);
|
m_queue.swap(q);
|
||||||
while (!q.empty() && amount > 0)
|
while (!q.empty() && amount > 0)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(amount == limit - m_current_quota);
|
|
||||||
bw_queue_entry<PeerConnection> qe = q.front();
|
bw_queue_entry<PeerConnection> qe = q.front();
|
||||||
TORRENT_ASSERT(qe.max_block_size > 0);
|
TORRENT_ASSERT(qe.max_block_size > 0);
|
||||||
q.pop_front();
|
q.pop_front();
|
||||||
|
@ -325,7 +330,6 @@ private:
|
||||||
l.unlock();
|
l.unlock();
|
||||||
t->expire_bandwidth(m_channel, qe.max_block_size);
|
t->expire_bandwidth(m_channel, qe.max_block_size);
|
||||||
l.lock();
|
l.lock();
|
||||||
amount = limit - m_current_quota;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +339,7 @@ private:
|
||||||
int max_assignable = qe.peer->max_assignable_bandwidth(m_channel);
|
int max_assignable = qe.peer->max_assignable_bandwidth(m_channel);
|
||||||
if (max_assignable == 0)
|
if (max_assignable == 0)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_in_history(qe.peer.get()));
|
TORRENT_ASSERT(is_in_history(qe.peer.get(), l));
|
||||||
tmp.push_back(qe);
|
tmp.push_back(qe);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -391,7 +395,6 @@ private:
|
||||||
int hand_out_amount = (std::min)((std::min)(block_size, max_assignable)
|
int hand_out_amount = (std::min)((std::min)(block_size, max_assignable)
|
||||||
, amount);
|
, amount);
|
||||||
TORRENT_ASSERT(hand_out_amount > 0);
|
TORRENT_ASSERT(hand_out_amount > 0);
|
||||||
TORRENT_ASSERT(amount == limit - m_current_quota);
|
|
||||||
amount -= hand_out_amount;
|
amount -= hand_out_amount;
|
||||||
TORRENT_ASSERT(hand_out_amount <= qe.max_block_size);
|
TORRENT_ASSERT(hand_out_amount <= qe.max_block_size);
|
||||||
l.unlock();
|
l.unlock();
|
||||||
|
@ -400,7 +403,6 @@ private:
|
||||||
l.lock();
|
l.lock();
|
||||||
add_history_entry(history_entry<PeerConnection, Torrent>(
|
add_history_entry(history_entry<PeerConnection, Torrent>(
|
||||||
qe.peer, t, hand_out_amount, now + bw_window_size));
|
qe.peer, t, hand_out_amount, now + bw_window_size));
|
||||||
amount = limit - m_current_quota;
|
|
||||||
}
|
}
|
||||||
if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end());
|
if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end());
|
||||||
if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end());
|
if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end());
|
||||||
|
|
Loading…
Reference in New Issue