removed redundant code in disk_io_thread

This commit is contained in:
Arvid Norberg
2009-07-21 04:32:27 +00:00
parent 11d89dd121
commit ecdd7231b8
3 changed files with 9 additions and 13 deletions

View File

@@ -152,6 +152,8 @@ namespace libtorrent
// the number of read operations used // the number of read operations used
size_type reads; size_type reads;
mutable size_type queued_bytes;
// the number of blocks in the cache (both read and write) // the number of blocks in the cache (both read and write)
int cache_size; int cache_size;
@@ -253,14 +255,11 @@ namespace libtorrent
, boost::function<void(int, disk_io_job const&)> const& f , boost::function<void(int, disk_io_job const&)> const& f
= boost::function<void(int, disk_io_job const&)>()); = boost::function<void(int, disk_io_job const&)>());
int queued_write_bytes() const;
// keep track of the number of bytes in the job queue // keep track of the number of bytes in the job queue
// at any given time. i.e. the sum of all buffer_size. // at any given time. i.e. the sum of all buffer_size.
// this is used to slow down the download global download // this is used to slow down the download global download
// speed when the queue buffer size is too big. // speed when the queue buffer size is too big.
size_type queue_buffer_size() const size_type queue_buffer_size() const;
{ return m_queue_buffer_size; }
void get_cache_info(sha1_hash const& ih void get_cache_info(sha1_hash const& ih
, std::vector<cached_piece_info>& ret) const; , std::vector<cached_piece_info>& ret) const;
@@ -362,8 +361,6 @@ namespace libtorrent
// exceed m_cache_size // exceed m_cache_size
cache_status m_cache_stats; cache_status m_cache_stats;
int m_queued_write_bytes;
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
std::ofstream m_log; std::ofstream m_log;
#endif #endif

View File

@@ -279,7 +279,6 @@ namespace libtorrent
, m_waiting_to_shutdown(false) , m_waiting_to_shutdown(false)
, m_queue_buffer_size(0) , m_queue_buffer_size(0)
, m_last_file_check(time_now_hires()) , m_last_file_check(time_now_hires())
, m_queued_write_bytes(0)
, m_ios(ios) , m_ios(ios)
, m_queue_callback(queue_callback) , m_queue_callback(queue_callback)
, m_work(io_service::work(m_ios)) , m_work(io_service::work(m_ios))
@@ -349,6 +348,7 @@ namespace libtorrent
{ {
mutex_t::scoped_lock l(m_piece_mutex); mutex_t::scoped_lock l(m_piece_mutex);
m_cache_stats.total_used_buffers = in_use(); m_cache_stats.total_used_buffers = in_use();
m_cache_stats.queued_bytes = m_queue_buffer_size;
return m_cache_stats; return m_cache_stats;
} }
@@ -1194,10 +1194,10 @@ namespace libtorrent
return ret; return ret;
} }
int disk_io_thread::queued_write_bytes() const size_type disk_io_thread::queue_buffer_size() const
{ {
mutex_t::scoped_lock l(m_queue_mutex); mutex_t::scoped_lock l(m_queue_mutex);
return m_queued_write_bytes; return m_queue_buffer_size;
} }
void disk_io_thread::add_job(disk_io_job const& j void disk_io_thread::add_job(disk_io_job const& j
@@ -1235,7 +1235,6 @@ namespace libtorrent
} }
else if (j.action == disk_io_job::write) else if (j.action == disk_io_job::write)
{ {
m_queued_write_bytes += j.buffer_size;
for (; i != m_jobs.rend(); ++i) for (; i != m_jobs.rend(); ++i)
{ {
if (*i < j) if (*i < j)
@@ -1347,7 +1346,8 @@ namespace libtorrent
if (m_queue_buffer_size + j.buffer_size >= m_settings.max_queued_disk_bytes if (m_queue_buffer_size + j.buffer_size >= m_settings.max_queued_disk_bytes
&& m_queue_buffer_size < m_settings.max_queued_disk_bytes && m_queue_buffer_size < m_settings.max_queued_disk_bytes
&& m_queue_callback) && m_queue_callback
&& m_settings.max_queued_disk_bytes > 0)
{ {
// we just dropped below the high watermark of number of bytes // we just dropped below the high watermark of number of bytes
// queued for writing to the disk. Notify the session so that it // queued for writing to the disk. Notify the session so that it
@@ -1568,7 +1568,6 @@ namespace libtorrent
} }
case disk_io_job::write: case disk_io_job::write:
{ {
m_queued_write_bytes -= j.buffer_size;
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
m_log << log_time() << " write " << j.buffer_size << std::endl; m_log << log_time() << " write " << j.buffer_size << std::endl;
#endif #endif

View File

@@ -1614,7 +1614,7 @@ ret:
int piece_manager::queued_bytes() const int piece_manager::queued_bytes() const
{ {
return m_io_thread.queued_write_bytes(); return m_io_thread.queue_buffer_size();
} }
void piece_manager::async_write( void piece_manager::async_write(