forked from premiere/premiere-libtorrent
added priority to disk io jobs
This commit is contained in:
parent
5b8ce7f6a0
commit
9364a2d01d
|
@ -50,6 +50,7 @@ namespace libtorrent
|
|||
, buffer_size(0)
|
||||
, piece(0)
|
||||
, offset(0)
|
||||
, priority(0)
|
||||
{}
|
||||
|
||||
enum action_t
|
||||
|
@ -72,6 +73,12 @@ namespace libtorrent
|
|||
// to the error message
|
||||
std::string str;
|
||||
|
||||
// priority decides whether or not this
|
||||
// job will skip entries in the queue or
|
||||
// not. It always skips in front of entries
|
||||
// with lower priority
|
||||
int priority;
|
||||
|
||||
// this is called when operation completes
|
||||
boost::function<void(int, disk_io_job const&)> callback;
|
||||
};
|
||||
|
|
|
@ -202,7 +202,8 @@ namespace libtorrent
|
|||
void async_read(
|
||||
peer_request const& r
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler
|
||||
, char* buffer = 0);
|
||||
, char* buffer = 0
|
||||
, int priority = 0);
|
||||
|
||||
void async_write(
|
||||
peer_request const& r
|
||||
|
|
|
@ -89,8 +89,15 @@ namespace libtorrent
|
|||
|
||||
namespace
|
||||
{
|
||||
// The semantic of this operator is:
|
||||
// shouls lhs come before rhs in the job queue
|
||||
bool operator<(disk_io_job const& lhs, disk_io_job const& rhs)
|
||||
{
|
||||
// NOTE: comparison inverted to make higher priority
|
||||
// skip _in_front_of_ lower priority
|
||||
if (lhs.priority > rhs.priority) return true;
|
||||
if (lhs.priority < rhs.priority) return false;
|
||||
|
||||
if (lhs.storage.get() < rhs.storage.get()) return true;
|
||||
if (lhs.storage.get() > rhs.storage.get()) return false;
|
||||
if (lhs.piece < rhs.piece) return true;
|
||||
|
|
|
@ -1084,7 +1084,8 @@ namespace libtorrent
|
|||
void piece_manager::async_read(
|
||||
peer_request const& r
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler
|
||||
, char* buffer)
|
||||
, char* buffer
|
||||
, int priority)
|
||||
{
|
||||
disk_io_job j;
|
||||
j.storage = this;
|
||||
|
@ -1093,6 +1094,7 @@ namespace libtorrent
|
|||
j.offset = r.start;
|
||||
j.buffer_size = r.length;
|
||||
j.buffer = buffer;
|
||||
j.priority = priority;
|
||||
// if a buffer is not specified, only one block can be read
|
||||
// since that is the size of the pool allocator's buffers
|
||||
assert(r.length <= 16 * 1024 || buffer != 0);
|
||||
|
|
Loading…
Reference in New Issue