fixed bug in storage::read()

This commit is contained in:
Daniel Wallin 2003-12-08 08:55:24 +00:00
parent 3ed0745cb1
commit 3849f449fc
1 changed files with 15 additions and 4 deletions

View File

@ -1421,7 +1421,7 @@ namespace libtorrent {
{ {
int read_bytes = left_to_read; int read_bytes = left_to_read;
if (file_offset + read_bytes > file_iter->size) if (file_offset + read_bytes > file_iter->size)
read_bytes = file_iter->size - offset; read_bytes = file_iter->size - file_offset;
assert(read_bytes > 0); assert(read_bytes > 0);
@ -1575,9 +1575,9 @@ namespace libtorrent {
boost::recursive_mutex::scoped_lock lock(m_mutex); boost::recursive_mutex::scoped_lock lock(m_mutex);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
m_allocating = false;
m_piece_to_slot.resize(m_info.num_pieces(), -1); m_piece_to_slot.resize(m_info.num_pieces(), -1);
m_slot_to_piece.resize(m_info.num_pieces(), -1); m_slot_to_piece.resize(m_info.num_pieces(), -1);
m_locked_pieces.resize(m_info.num_pieces(), false);
m_bytes_left = m_info.total_size(); m_bytes_left = m_info.total_size();
@ -1684,7 +1684,7 @@ namespace libtorrent {
} }
seek_into_next = pos - file_end; seek_into_next = pos - file_end;
bytes_to_read = piece_size; bytes_to_read = m_info.piece_size(current_piece);
piece_offset = 0; piece_offset = 0;
} }
else else
@ -1876,6 +1876,15 @@ namespace libtorrent {
void piece_manager::allocate_slots(int num_slots) void piece_manager::allocate_slots(int num_slots)
{ {
{
boost::mutex::scoped_lock lock(m_allocating_monitor);
while (m_allocating)
m_allocating_condition.wait(lock);
m_allocating = true;
}
// synchronization ------------------------------------------------------ // synchronization ------------------------------------------------------
boost::recursive_mutex::scoped_lock lock(m_mutex); boost::recursive_mutex::scoped_lock lock(m_mutex);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -1920,6 +1929,8 @@ namespace libtorrent {
m_unallocated_slots.erase(m_unallocated_slots.begin(), iter); m_unallocated_slots.erase(m_unallocated_slots.begin(), iter);
m_allocating = false;
check_invariant(); check_invariant();
} }