disk io thread cleanup (all read operations are now read into disk buffers, no custom buffers)

This commit is contained in:
Arvid Norberg 2008-04-10 09:11:54 +00:00
parent 2c77ae8307
commit 5f35d170b0
3 changed files with 17 additions and 17 deletions

View File

@ -212,7 +212,6 @@ namespace libtorrent
void async_read( void async_read(
peer_request const& r peer_request const& r
, boost::function<void(int, disk_io_job const&)> const& handler , boost::function<void(int, disk_io_job const&)> const& handler
, char* buffer = 0
, int priority = 0); , int priority = 0);
void async_write( void async_write(

View File

@ -741,7 +741,6 @@ namespace libtorrent
int ret = 0; int ret = 0;
bool allocated_buffer = false;
TORRENT_ASSERT(j.storage); TORRENT_ASSERT(j.storage);
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
ptime start = time_now(); ptime start = time_now();
@ -770,17 +769,14 @@ namespace libtorrent
#endif #endif
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_ASSERT(j.buffer == 0);
j.buffer = allocate_buffer();
TORRENT_ASSERT(j.buffer_size <= m_block_size);
if (j.buffer == 0) if (j.buffer == 0)
{ {
j.buffer = allocate_buffer(); ret = -1;
allocated_buffer = true; j.str = "out of memory";
TORRENT_ASSERT(j.buffer_size <= m_block_size); break;
if (j.buffer == 0)
{
ret = -1;
j.str = "out of memory";
break;
}
} }
ret = try_read_from_cache(j, l); ret = try_read_from_cache(j, l);
@ -789,7 +785,7 @@ namespace libtorrent
// or that the read cache is disabled // or that the read cache is disabled
if (ret == -1) if (ret == -1)
{ {
if (allocated_buffer) free_buffer(j.buffer, l); free_buffer(j.buffer, l);
j.buffer = 0; j.buffer = 0;
j.str = j.storage->error(); j.str = j.storage->error();
j.storage->clear_error(); j.storage->clear_error();
@ -802,7 +798,7 @@ namespace libtorrent
, j.buffer_size); , j.buffer_size);
if (ret < 0) if (ret < 0)
{ {
if (allocated_buffer) free_buffer(j.buffer); free_buffer(j.buffer);
j.str = j.storage->error(); j.str = j.storage->error();
j.storage->clear_error(); j.storage->clear_error();
break; break;
@ -876,6 +872,7 @@ namespace libtorrent
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
m_log << log_time() << " move" << std::endl; m_log << log_time() << " move" << std::endl;
#endif #endif
TORRENT_ASSERT(j.buffer == 0);
ret = j.storage->move_storage_impl(j.str) ? 1 : 0; ret = j.storage->move_storage_impl(j.str) ? 1 : 0;
if (ret != 0) if (ret != 0)
{ {
@ -891,6 +888,7 @@ namespace libtorrent
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
m_log << log_time() << " release" << std::endl; m_log << log_time() << " release" << std::endl;
#endif #endif
TORRENT_ASSERT(j.buffer == 0);
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);
INVARIANT_CHECK; INVARIANT_CHECK;
@ -924,6 +922,7 @@ namespace libtorrent
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
m_log << log_time() << " delete" << std::endl; m_log << log_time() << " delete" << std::endl;
#endif #endif
TORRENT_ASSERT(j.buffer == 0);
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1017,7 +1016,10 @@ namespace libtorrent
#endif #endif
if (handler) m_ios.post(bind(handler, ret, j)); if (handler) m_ios.post(bind(handler, ret, j));
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) {} } catch (std::exception&)
{
if (j.buffer) free_buffer(j.buffer);
}
#endif #endif
} }
TORRENT_ASSERT(false); TORRENT_ASSERT(false);

View File

@ -1221,7 +1221,6 @@ namespace libtorrent
void piece_manager::async_read( void piece_manager::async_read(
peer_request const& r peer_request const& r
, boost::function<void(int, disk_io_job const&)> const& handler , boost::function<void(int, disk_io_job const&)> const& handler
, char* buffer
, int priority) , int priority)
{ {
disk_io_job j; disk_io_job j;
@ -1230,11 +1229,11 @@ namespace libtorrent
j.piece = r.piece; j.piece = r.piece;
j.offset = r.start; j.offset = r.start;
j.buffer_size = r.length; j.buffer_size = r.length;
j.buffer = buffer; j.buffer = 0;
j.priority = priority; j.priority = priority;
// if a buffer is not specified, only one block can be read // if a buffer is not specified, only one block can be read
// since that is the size of the pool allocator's buffers // since that is the size of the pool allocator's buffers
TORRENT_ASSERT(r.length <= 16 * 1024 || buffer != 0); TORRENT_ASSERT(r.length <= 16 * 1024);
m_io_thread.add_job(j, handler); m_io_thread.add_job(j, handler);
#ifndef NDEBUG #ifndef NDEBUG
boost::recursive_mutex::scoped_lock l(m_mutex); boost::recursive_mutex::scoped_lock l(m_mutex);