merged file priority fix from RC_0_16 and keep the disk thread's file priorities up to date

This commit is contained in:
Arvid Norberg 2014-02-28 10:19:29 +00:00
parent 86c704a6ff
commit a0a41b6c5e
8 changed files with 61 additions and 3 deletions

View File

@ -41,6 +41,7 @@
* fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP
* improve support for de-selected files in full allocation mode
* fix dht_bootstrap_alert being posted
* SetFileValidData fix on windows (prevents zero-fill)
* fix minor lock_files issue on unix

View File

@ -116,6 +116,7 @@ namespace libtorrent
, update_settings
, read_and_hash
, cache_piece
, file_priority
#ifndef TORRENT_NO_DEPRECATE
, finalize_file
#endif

View File

@ -75,6 +75,7 @@ POSSIBILITY OF SUCH DAMAGE.
// struct temp_storage : storage_interface
// {
// temp_storage(file_storage const& fs) : m_files(fs) {}
// void set_file_priority(std::vector<boost::uint8_t> const& prio) {}
// virtual bool initialize(bool allocate_files) { return false; }
// virtual bool has_any_file() { return false; }
// virtual int read(char* buf, int slot, int offset, int size)
@ -193,6 +194,7 @@ namespace libtorrent
// hidden
storage_interface(): m_disk_pool(0), m_settings(0) {}
// This function is called when the storage is to be initialized. The default storage
// will create directories and empty files at this point. If ``allocate_files`` is true,
// it will also ``ftruncate`` all files to their target size.
@ -205,6 +207,10 @@ namespace libtorrent
// If so, the storage will be checked for existing pieces before starting the download.
virtual bool has_any_file() = 0;
// change the priorities of files.
virtual void set_file_priority(std::vector<boost::uint8_t> const& prio) = 0;
// These functions should read or write the data in or to the given ``slot`` at the given ``offset``.
// It should read or write ``num_bufs`` buffers sequentially, where the size of each buffer
// is specified in the buffer array ``bufs``. The file::iovec_t type has the following members::
@ -407,6 +413,7 @@ namespace libtorrent
// hidden
~default_storage();
void set_file_priority(std::vector<boost::uint8_t> const& prio);
#ifndef TORRENT_NO_DEPRECATE
void finalize_file(int file);
#endif
@ -495,6 +502,7 @@ namespace libtorrent
{
public:
disabled_storage(int piece_size) : m_piece_size(piece_size) {}
void set_file_priority(std::vector<boost::uint8_t> const& prio) {}
bool has_any_file() { return false; }
bool rename_file(int, std::string const&) { return false; }
bool release_files() { return false; }
@ -609,6 +617,10 @@ namespace libtorrent
void async_move_storage(std::string const& p, int flags
, boost::function<void(int, disk_io_job const&)> const& handler);
void async_set_file_priority(
std::vector<boost::uint8_t> const& prios
, boost::function<void(int, disk_io_job const&)> const& handler);
void async_save_resume_data(
boost::function<void(int, disk_io_job const&)> const& handler);
@ -707,6 +719,8 @@ namespace libtorrent
int delete_files_impl() { return m_storage->delete_files(); }
int rename_file_impl(int index, std::string const& new_filename)
{ return m_storage->rename_file(index, new_filename); }
void set_file_priority_impl(std::vector<boost::uint8_t> const& p)
{ m_storage->set_file_priority(p); }
int move_storage_impl(std::string const& save_path, int flags);

View File

@ -2486,8 +2486,17 @@ namespace libtorrent
if (ret != 0)
{
test_error(j);
break;
}
break;
}
case disk_io_job::file_priority:
{
std::vector<boost::uint8_t>* p
= reinterpret_cast<std::vector<boost::uint8_t>*>(j.buffer);
j.storage->set_file_priority_impl(*p);
delete p;
ret = 0;
break;
}
}
}

View File

@ -397,6 +397,11 @@ namespace libtorrent
default_storage::~default_storage() { m_pool.release(this); }
void default_storage::set_file_priority(std::vector<boost::uint8_t> const& prio)
{
m_file_priority = prio;
}
bool default_storage::initialize(bool allocate_files)
{
m_allocate_files = allocate_files;
@ -457,7 +462,6 @@ namespace libtorrent
ec.clear();
}
std::vector<boost::uint8_t>().swap(m_file_priority);
// close files that were opened in write mode
m_pool.release(this);
@ -1525,6 +1529,19 @@ ret:
{
}
void piece_manager::async_set_file_priority(
std::vector<boost::uint8_t> const& prios
, boost::function<void(int, disk_io_job const&)> const& handler)
{
std::vector<boost::uint8_t>* p = new std::vector<boost::uint8_t>(prios);
disk_io_job j;
j.storage = this;
j.buffer = (char*)p;
j.action = disk_io_job::file_priority;
m_io_thread.add_job(j, handler);
}
void piece_manager::async_save_resume_data(
boost::function<void(int, disk_io_job const&)> const& handler)
{

View File

@ -3964,6 +3964,8 @@ namespace libtorrent
}
}
void nop() {}
void torrent::prioritize_files(std::vector<int> const& files)
{
INVARIANT_CHECK;
@ -3989,6 +3991,13 @@ namespace libtorrent
if (valid_metadata() && m_torrent_file->num_files() > int(m_file_priority.size()))
m_file_priority.resize(m_torrent_file->num_files(), 1);
// stoage may be NULL during shutdown
if (m_torrent_file->num_pieces() > 0 && m_storage)
{
filesystem().async_set_file_priority(m_file_priority
, boost::bind(&nop));
}
update_piece_priorities();
}
@ -4009,6 +4018,12 @@ namespace libtorrent
}
if (m_file_priority[index] == prio) return;
m_file_priority[index] = prio;
// stoage may be NULL during shutdown
if (m_storage)
{
filesystem().async_set_file_priority(m_file_priority
, boost::bind(&nop));
}
update_piece_priorities();
}

View File

@ -167,7 +167,7 @@ struct test_storage : storage_interface
virtual bool initialize(bool allocate_files) { return true; }
virtual bool has_any_file() { return true; }
virtual void set_file_priority(std::vector<boost::uint8_t> const& p) {}
int write(
const char* buf

View File

@ -77,6 +77,7 @@ struct test_storage : storage_interface
, m_written(0)
, m_limit(16 * 1024 * 2)
{}
virtual void set_file_priority(std::vector<boost::uint8_t> const& p) {}
virtual bool initialize(bool allocate_files)
{ return m_lower_layer->initialize(allocate_files); }