made disk_io_settings be synchronized through the job queue

This commit is contained in:
Arvid Norberg 2009-01-10 05:46:02 +00:00
parent c21edfa6f1
commit cfd116ffad
5 changed files with 43 additions and 20 deletions

View File

@ -3193,6 +3193,7 @@ that will be sent to the tracker. The user-agent is a good way to identify your
bool use_parole_mode;
int cache_size;
int cache_expiry;
bool use_read_cache;
std::pair<int, int> outgoing_ports;
char peer_tos;
@ -3420,6 +3421,9 @@ It defaults to 512 (= 8 MB).
``cache_expiry`` is the number of seconds from the last cached write to a piece
in the write cache, to when it's forcefully flushed to disk. Default is 60 second.
``use_read_cache``, is set to true (default), the disk cache is also used to
cache pieces read from disk. Blocks for writing pieces takes presedence.
``outgoing_ports``, if set to something other than (0, 0) is a range of ports
used to bind outgoing sockets to. This may be useful for users whose router
allows them to assign QoS classes to traffic based on its local port. It is

View File

@ -89,6 +89,7 @@ namespace libtorrent
, abort_thread
, clear_read_cache
, abort_torrent
, update_settings
};
action_t action;
@ -186,8 +187,6 @@ namespace libtorrent
, std::vector<cached_piece_info>& ret) const;
cache_status status() const;
void set_cache_size(int s);
void set_cache_expiry(int ex);
void operator()();

View File

@ -124,6 +124,7 @@ namespace libtorrent
, use_parole_mode(true)
, cache_size(512)
, cache_expiry(60)
, use_read_cache(true)
, outgoing_ports(0,0)
, peer_tos(0)
, active_downloads(8)
@ -372,6 +373,10 @@ namespace libtorrent
// to disk. Default is 60 seconds.
int cache_expiry;
// when true, the disk I/O thread uses the disk
// cache for caching blocks read from disk too
bool use_read_cache;
// if != (0, 0), this is the range of ports that
// outgoing connections will be bound to. This
// is useful for users that have routers that

View File

@ -145,20 +145,6 @@ namespace libtorrent
return m_cache_stats;
}
void disk_io_thread::set_cache_size(int s)
{
mutex_t::scoped_lock l(m_piece_mutex);
TORRENT_ASSERT(s >= 0);
m_cache_size = s;
}
void disk_io_thread::set_cache_expiry(int ex)
{
mutex_t::scoped_lock l(m_piece_mutex);
TORRENT_ASSERT(ex > 0);
m_cache_expiry = ex;
}
// aborts read operations
void disk_io_thread::stop(boost::intrusive_ptr<piece_manager> s)
{
@ -870,6 +856,21 @@ namespace libtorrent
switch (j.action)
{
case disk_io_job::update_settings:
{
#ifdef TORRENT_DISK_STATS
m_log << log_time() << " update_settings " << std::endl;
#endif
TORRENT_ASSERT(j.buffer);
session_settings const& s = *((session_settings*)j.buffer);
TORRENT_ASSERT(s.cache_size >= 0);
TORRENT_ASSERT(s.cache_expiry > 0);
mutex_t::scoped_lock l(m_piece_mutex);
m_cache_size = s.cache_size;
m_cache_expiry = s.cache_expiry;
m_use_read_cache = s.use_read_cache;
}
case disk_io_job::abort_torrent:
{
#ifdef TORRENT_DISK_STATS

View File

@ -582,10 +582,16 @@ namespace aux {
// less than 5 seconds unchoke interval is insane
TORRENT_ASSERT(s.unchoke_interval >= 5);
if (m_settings.cache_size != s.cache_size)
m_disk_thread.set_cache_size(s.cache_size);
if (m_settings.cache_expiry != s.cache_expiry)
m_disk_thread.set_cache_expiry(s.cache_expiry);
// if disk io thread settings were changed
// post a notification to that thread
bool update_disk_io_thread = false;
if (m_settings.cache_size != s.cache_size
|| m_settings.cache_expiry != s.cache_expiry
|| m_settings.use_read_cache != s.use_read_cache)
update_disk_io_thread = true;
// if queuing settings were changed, recalculate
// queued torrents sooner
if ((m_settings.active_downloads != s.active_downloads
@ -596,6 +602,14 @@ namespace aux {
m_settings = s;
if (m_settings.connection_speed <= 0) m_settings.connection_speed = 200;
if (update_disk_io_thread)
{
disk_io_job j;
j.buffer = (char*)&m_settings;
j.action = disk_io_job::update_settings;
m_disk_thread.add_job(j);
}
m_files.resize(m_settings.file_pool_size);
if (!s.auto_upload_slots) m_allowed_upload_slots = m_max_uploads;
// replace all occurances of '\n' with ' '.