mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 05:32:31 +00:00
* Removed ticks for downloads, use the global tick instead.
* Fixed rak::priority_queue. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@608 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -47,32 +47,35 @@ namespace rak {
|
||||
|
||||
class priority_item {
|
||||
public:
|
||||
bool is_queued() const { return m_time != timer(); }
|
||||
priority_item() {}
|
||||
~priority_item() {
|
||||
if (is_queued())
|
||||
throw std::logic_error("priority_item::~priority_item() called on a queued item.");
|
||||
|
||||
void call() { m_slot(); }
|
||||
void set_slot(function<void> s) { m_slot = s; }
|
||||
m_time = timer();
|
||||
m_slot.set(NULL);
|
||||
}
|
||||
|
||||
bool is_valid() const { return m_slot.is_valid(); }
|
||||
bool is_queued() const { return m_time != timer(); }
|
||||
|
||||
void call() { m_slot(); }
|
||||
void set_slot(function_base<void>* s) { m_slot.set(s); }
|
||||
|
||||
const timer& time() const { return m_time; }
|
||||
const timer& time() const { return m_time; }
|
||||
void clear_time() { m_time = timer(); }
|
||||
void set_time(const timer& t) { m_time = t; }
|
||||
|
||||
priority_item* prepare(const timer& t);
|
||||
priority_item* clear() { m_time = timer(); return this; }
|
||||
|
||||
bool compare(const timer& t) const { return m_time > t; }
|
||||
bool compare(const timer& t) const { return m_time > t; }
|
||||
|
||||
private:
|
||||
priority_item(const priority_item&);
|
||||
void operator = (const priority_item&);
|
||||
|
||||
timer m_time;
|
||||
function<void> m_slot;
|
||||
};
|
||||
|
||||
inline priority_item*
|
||||
priority_item::prepare(const timer& t) {
|
||||
if (is_queued())
|
||||
throw std::logic_error("priority_item::prepare(rak::timer) called on an already queued item.");
|
||||
|
||||
m_time = t;
|
||||
return this;
|
||||
}
|
||||
|
||||
struct priority_compare {
|
||||
bool operator () (const priority_item* const p1, const priority_item* const p2) const {
|
||||
return p1->time() > p2->time();
|
||||
@@ -82,6 +85,42 @@ struct priority_compare {
|
||||
typedef std::equal_to<priority_item*> priority_equal;
|
||||
typedef priority_queue<priority_item*, priority_compare, priority_equal> priority_queue_default;
|
||||
|
||||
inline void
|
||||
priority_queue_insert(priority_queue_default* queue, priority_item* item, timer t) {
|
||||
if (t == timer())
|
||||
throw std::logic_error("priority_queue_insert(...) received a bad timer.");
|
||||
|
||||
if (!item->is_valid())
|
||||
throw std::logic_error("priority_queue_insert(...) called on an invalid item.");
|
||||
|
||||
if (item->is_queued())
|
||||
throw std::logic_error("priority_queue_insert(...) called on an already queued item.");
|
||||
|
||||
if (queue->find(item) != queue->end())
|
||||
throw std::logic_error("priority_queue_insert(...) item found in queue.");
|
||||
|
||||
item->set_time(t);
|
||||
queue->push(item);
|
||||
}
|
||||
|
||||
inline void
|
||||
priority_queue_erase(priority_queue_default* queue, priority_item* item) {
|
||||
if (!item->is_valid())
|
||||
throw std::logic_error("priority_queue_erase(...) called on an invalid item.");
|
||||
|
||||
if (!item->is_queued())
|
||||
return;
|
||||
|
||||
// Clear time before erasing to force it to the top.
|
||||
item->clear_time();
|
||||
|
||||
if (!queue->erase(item))
|
||||
throw std::logic_error("priority_queue_erase(...) could not find item in queue.");
|
||||
|
||||
if (queue->find(item) != queue->end())
|
||||
throw std::logic_error("priority_queue_erase(...) item still in queue.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user