mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-08 19:22:29 +00:00
* Changed the TaskScheduler so new tasks are inserted beyond the last
due task when executing. * Moved stuff from torrent/torrent.cc to torrent::Manager. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@535 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
||||
AC_INIT(rtorrent, 0.3.2, jaris@ifi.uio.no)
|
||||
AC_INIT(rtorrent, 0.3.3, jaris@ifi.uio.no)
|
||||
|
||||
AM_INIT_AUTOMAKE
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
@@ -22,7 +22,7 @@ TORRENT_OTFD()
|
||||
|
||||
TORRENT_WITHOUT_VARIABLE_FDSET()
|
||||
|
||||
PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.7.2,
|
||||
PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.7.3,
|
||||
CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS $CURL_CFLAGS";
|
||||
LIBS="$LIBS $STUFF_LIBS $CURL_LIBS")
|
||||
|
||||
|
||||
+24
-17
@@ -43,24 +43,21 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
inline void
|
||||
TaskScheduler::execute_task(const value_type& v) {
|
||||
if (!is_scheduled(v.second))
|
||||
throw std::logic_error("TaskScheduler::execute_task(iterator) received an invalid iterator");
|
||||
|
||||
v.second->set_iterator(end());
|
||||
v.second->get_slot()();
|
||||
}
|
||||
|
||||
void
|
||||
TaskScheduler::insert(TaskItem* task, Timer time) {
|
||||
if (is_scheduled(task))
|
||||
throw std::logic_error("TaskScheduler::insert(...) tried to insert an already inserted or invalid TaskItem");
|
||||
|
||||
iterator itr = std::find_if(begin(), end(),
|
||||
rak::less_equal(time, rak::mem_ptr_ref(&value_type::first)));
|
||||
// Only insert at or after m_entry because if we might be in
|
||||
// execute(...).
|
||||
iterator itr = std::find_if(m_entry, end(), rak::less_equal(time, rak::mem_ptr_ref(&value_type::first)));
|
||||
|
||||
task->set_iterator(Base::insert(itr, value_type(time, task)));
|
||||
|
||||
// Make sure m_entry points to the right node if we try inserting
|
||||
// before m_entry.
|
||||
if (itr == m_entry)
|
||||
m_entry = task->get_iterator();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -68,19 +65,29 @@ TaskScheduler::erase(TaskItem* task) {
|
||||
if (!is_scheduled(task))
|
||||
return;
|
||||
|
||||
Base::erase(task->get_iterator());
|
||||
iterator itr = Base::erase(task->get_iterator());
|
||||
|
||||
if (task->get_iterator() == m_entry)
|
||||
m_entry = itr;
|
||||
|
||||
task->set_iterator(end());
|
||||
}
|
||||
|
||||
void
|
||||
TaskScheduler::execute(Timer time) {
|
||||
Base tmp;
|
||||
m_entry = std::find_if(begin(), end(), rak::less_equal(time, rak::mem_ptr_ref(&value_type::first)));
|
||||
|
||||
tmp.splice(tmp.begin(), *this,
|
||||
begin(), std::find_if(begin(), end(), rak::less_equal(time, rak::mem_ptr_ref(&value_type::first))));
|
||||
// Since we are always using the front rather than a splice of the
|
||||
// due tasks, it is safe to erase them from within other tasks.
|
||||
while (begin() != m_entry) {
|
||||
if (!is_scheduled(Base::front().second))
|
||||
throw std::logic_error("TaskScheduler::execute_task(iterator) received an invalid iterator");
|
||||
|
||||
Base::front().second->set_iterator(end());
|
||||
Base::front().second->get_slot()();
|
||||
|
||||
std::for_each(tmp.begin(), tmp.end(),
|
||||
rak::bind1st(std::mem_fun(&TaskScheduler::execute_task), this));
|
||||
Base::pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ public:
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
|
||||
TaskScheduler() : m_entry(begin()) {}
|
||||
|
||||
void insert(TaskItem* task, Timer time);
|
||||
void erase(TaskItem* task);
|
||||
|
||||
@@ -68,7 +70,7 @@ public:
|
||||
Timer get_next_timeout() const { return begin()->first; }
|
||||
|
||||
private:
|
||||
inline void execute_task(const value_type& v);
|
||||
iterator m_entry;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user