mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-13 12:46:18 +00:00
* Moved Timer to rak/timer.h.
* Added position affinity to ChunkSelector, still needs more work to make it move forward without needing to finish all pieces. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@604 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -8,6 +8,7 @@ EXTRA_DIST= \
|
|||||||
rak/error_number.h \
|
rak/error_number.h \
|
||||||
rak/functional.h \
|
rak/functional.h \
|
||||||
rak/string_manip.h \
|
rak/string_manip.h \
|
||||||
|
rak/timer.h \
|
||||||
rak/unordered_vector.h \
|
rak/unordered_vector.h \
|
||||||
scripts/checks.m4 \
|
scripts/checks.m4 \
|
||||||
scripts/common.m4
|
scripts/common.m4
|
||||||
|
|||||||
+2
-2
@@ -38,6 +38,7 @@
|
|||||||
#define RAK_ALGORITHM_H
|
#define RAK_ALGORITHM_H
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace rak {
|
namespace rak {
|
||||||
|
|
||||||
@@ -90,8 +91,7 @@ advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __las
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename _Value>
|
template <typename _Value>
|
||||||
struct
|
struct compare_base : public std::binary_function<_Value, _Value, bool> {
|
||||||
compare_base : public std::binary_function<_Value, _Value, bool> {
|
|
||||||
bool operator () (const _Value& complete, const _Value& base) const {
|
bool operator () (const _Value& complete, const _Value& base) const {
|
||||||
return !complete.compare(0, base.size(), base);
|
return !complete.compare(0, base.size(), base);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// rTorrent - BitTorrent client
|
// libTorrent - BitTorrent library
|
||||||
// Copyright (C) 2005, Jari Sundell
|
// Copyright (C) 2005, Jari Sundell
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
@@ -34,63 +34,56 @@
|
|||||||
// Skomakerveien 33
|
// Skomakerveien 33
|
||||||
// 3185 Skoppum, NORWAY
|
// 3185 Skoppum, NORWAY
|
||||||
|
|
||||||
#ifndef RTORRENT_UTILS_TIMER_H
|
#ifndef RAK_TIMER_H
|
||||||
#define RTORRENT_UTILS_TIMER_H
|
#define RAK_TIMER_H
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
namespace utils {
|
namespace rak {
|
||||||
|
|
||||||
// Don't convert negative Timer to timeval and then back to Timer, that will bork.
|
// Don't convert negative Timer to timeval and then back to Timer, that will bork.
|
||||||
class Timer {
|
class timer {
|
||||||
public:
|
public:
|
||||||
Timer() : m_time(0) {}
|
timer() : m_time(0) {}
|
||||||
Timer(int64_t usec) : m_time(usec) {}
|
timer(int64_t usec) : m_time(usec) {}
|
||||||
Timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
|
timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
|
||||||
|
|
||||||
int32_t seconds() const { return m_time / 1000000; }
|
int32_t seconds() const { return m_time / 1000000; }
|
||||||
int64_t usec() const { return m_time; }
|
int64_t usec() const { return m_time; }
|
||||||
|
|
||||||
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
|
timer round_seconds() const { return (m_time / 1000000) * 1000000; }
|
||||||
|
|
||||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||||
|
|
||||||
static Timer current();
|
static timer current();
|
||||||
|
|
||||||
// Cached time, updated in the beginning of torrent::work call.
|
bool operator < (const timer& t) const { return m_time < t.m_time; }
|
||||||
// Don't use outside socket_base read/write/except or Service::service.
|
bool operator > (const timer& t) const { return m_time > t.m_time; }
|
||||||
static Timer cache() { return Timer(m_cache); }
|
bool operator <= (const timer& t) const { return m_time <= t.m_time; }
|
||||||
|
bool operator >= (const timer& t) const { return m_time >= t.m_time; }
|
||||||
|
bool operator == (const timer& t) const { return m_time == t.m_time; }
|
||||||
|
bool operator != (const timer& t) const { return m_time != t.m_time; }
|
||||||
|
|
||||||
static void update() { m_cache = Timer::current().usec(); }
|
timer operator - (const timer& t) const { return timer(m_time - t.m_time); }
|
||||||
|
timer operator + (const timer& t) const { return timer(m_time + t.m_time); }
|
||||||
|
|
||||||
bool operator < (const Timer& t) const { return m_time < t.m_time; }
|
timer operator -= (int64_t t) { m_time -= t; return *this; }
|
||||||
bool operator > (const Timer& t) const { return m_time > t.m_time; }
|
timer operator -= (const timer& t) { m_time -= t.m_time; return *this; }
|
||||||
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
|
|
||||||
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
|
|
||||||
|
|
||||||
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
|
timer operator += (int64_t t) { m_time += t; return *this; }
|
||||||
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
|
timer operator += (const timer& t) { m_time += t.m_time; return *this; }
|
||||||
|
|
||||||
Timer operator -= (int64_t t) { m_time -= t; return *this; }
|
|
||||||
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
|
|
||||||
|
|
||||||
Timer operator += (int64_t t) { m_time += t; return *this; }
|
|
||||||
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t m_time;
|
int64_t m_time;
|
||||||
|
|
||||||
// Instantiated in torrent.cc
|
|
||||||
static int64_t m_cache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Timer
|
inline timer
|
||||||
Timer::current() {
|
timer::current() {
|
||||||
timeval t;
|
timeval t;
|
||||||
gettimeofday(&t, 0);
|
gettimeofday(&t, 0);
|
||||||
|
|
||||||
return Timer(t);
|
return timer(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ rtorrent_LDADD = \
|
|||||||
rtorrent_SOURCES = \
|
rtorrent_SOURCES = \
|
||||||
control.cc \
|
control.cc \
|
||||||
control.h \
|
control.h \
|
||||||
|
globals.cc \
|
||||||
|
globals.h \
|
||||||
main.cc \
|
main.cc \
|
||||||
option_file.cc \
|
option_file.cc \
|
||||||
option_file.h \
|
option_file.h \
|
||||||
|
|||||||
+4
-4
@@ -59,7 +59,7 @@ Control::Control() :
|
|||||||
|
|
||||||
m_inputStdin->slot_pressed(sigc::mem_fun(m_input, &input::Manager::pressed));
|
m_inputStdin->slot_pressed(sigc::mem_fun(m_input, &input::Manager::pressed));
|
||||||
|
|
||||||
m_taskShutdown.set_iterator(utils::taskScheduler.end());
|
m_taskShutdown.set_iterator(taskScheduler.end());
|
||||||
m_taskShutdown.set_slot(sigc::mem_fun(*this, &Control::receive_shutdown));
|
m_taskShutdown.set_slot(sigc::mem_fun(*this, &Control::receive_shutdown));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ Control::initialize() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
Control::cleanup() {
|
Control::cleanup() {
|
||||||
utils::taskScheduler.erase(&m_taskShutdown);
|
taskScheduler.erase(&m_taskShutdown);
|
||||||
|
|
||||||
m_inputStdin->remove(m_core->get_poll_manager()->get_torrent_poll());
|
m_inputStdin->remove(m_core->get_poll_manager()->get_torrent_poll());
|
||||||
|
|
||||||
@@ -113,8 +113,8 @@ Control::receive_shutdown() {
|
|||||||
m_core->shutdown(false);
|
m_core->shutdown(false);
|
||||||
m_shutdownReceived = true;
|
m_shutdownReceived = true;
|
||||||
|
|
||||||
if (!utils::taskScheduler.is_scheduled(&m_taskShutdown))
|
if (!taskScheduler.is_scheduled(&m_taskShutdown))
|
||||||
utils::taskScheduler.insert(&m_taskShutdown, utils::Timer::cache() + 5 * 1000000);
|
taskScheduler.insert(&m_taskShutdown, cachedTime + 5 * 1000000);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_core->shutdown(true);
|
m_core->shutdown(true);
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
#include <torrent/torrent.h>
|
#include <torrent/torrent.h>
|
||||||
|
|
||||||
#include "utils/task.h"
|
#include "globals.h"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
class Root;
|
class Root;
|
||||||
|
|||||||
@@ -41,9 +41,9 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <torrent/bencode.h>
|
#include <torrent/bencode.h>
|
||||||
|
|
||||||
#include "utils/task.h"
|
|
||||||
#include "curl_get.h"
|
#include "curl_get.h"
|
||||||
#include "http_queue.h"
|
#include "http_queue.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
|
|
||||||
#include "download_factory.h"
|
#include "download_factory.h"
|
||||||
@@ -60,16 +60,16 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
|
|||||||
m_session(false),
|
m_session(false),
|
||||||
m_start(false) {
|
m_start(false) {
|
||||||
|
|
||||||
m_taskLoad.set_iterator(utils::taskScheduler.end());
|
m_taskLoad.set_iterator(taskScheduler.end());
|
||||||
m_taskLoad.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_load));
|
m_taskLoad.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_load));
|
||||||
|
|
||||||
m_taskCommit.set_iterator(utils::taskScheduler.end());
|
m_taskCommit.set_iterator(taskScheduler.end());
|
||||||
m_taskCommit.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_commit));
|
m_taskCommit.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_commit));
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadFactory::~DownloadFactory() {
|
DownloadFactory::~DownloadFactory() {
|
||||||
utils::taskScheduler.erase(&m_taskLoad);
|
taskScheduler.erase(&m_taskLoad);
|
||||||
utils::taskScheduler.erase(&m_taskCommit);
|
taskScheduler.erase(&m_taskCommit);
|
||||||
|
|
||||||
delete m_stream;
|
delete m_stream;
|
||||||
m_stream = NULL;
|
m_stream = NULL;
|
||||||
@@ -77,12 +77,12 @@ DownloadFactory::~DownloadFactory() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
DownloadFactory::load() {
|
DownloadFactory::load() {
|
||||||
utils::taskScheduler.insert(&m_taskLoad, utils::Timer::cache());
|
taskScheduler.insert(&m_taskLoad, cachedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadFactory::commit() {
|
DownloadFactory::commit() {
|
||||||
utils::taskScheduler.insert(&m_taskCommit, utils::Timer::cache());
|
taskScheduler.insert(&m_taskCommit, cachedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
+5
-4
@@ -37,15 +37,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <rak/functional.h>
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "rak/functional.h"
|
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
void
|
void
|
||||||
Log::push_front(const std::string& msg) {
|
Log::push_front(const std::string& msg) {
|
||||||
Base::push_front(Type(utils::Timer::cache(), msg));
|
Base::push_front(Type(cachedTime, msg));
|
||||||
|
|
||||||
if (size() > 50)
|
if (size() > 50)
|
||||||
Base::pop_back();
|
Base::pop_back();
|
||||||
@@ -54,8 +55,8 @@ Log::push_front(const std::string& msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log::iterator
|
Log::iterator
|
||||||
Log::find_older(utils::Timer t) {
|
Log::find_older(rak::timer t) {
|
||||||
return std::find_if(begin(), end(), rak::on(rak::mem_ptr_ref(&Type::first), std::bind2nd(std::less_equal<utils::Timer>(), t)));
|
return std::find_if(begin(), end(), rak::on(rak::mem_ptr_ref(&Type::first), std::bind2nd(std::less_equal<rak::timer>(), t)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -41,13 +41,13 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sigc++/signal.h>
|
#include <sigc++/signal.h>
|
||||||
|
|
||||||
#include "utils/timer.h"
|
#include <rak/timer.h>
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class Log : private std::deque<std::pair<utils::Timer, std::string> > {
|
class Log : private std::deque<std::pair<rak::timer, std::string> > {
|
||||||
public:
|
public:
|
||||||
typedef std::pair<utils::Timer, std::string> Type;
|
typedef std::pair<rak::timer, std::string> Type;
|
||||||
typedef std::deque<Type> Base;
|
typedef std::deque<Type> Base;
|
||||||
typedef sigc::signal0<void> Signal;
|
typedef sigc::signal0<void> Signal;
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
void push_front(const std::string& msg);
|
void push_front(const std::string& msg);
|
||||||
|
|
||||||
iterator find_older(utils::Timer t);
|
iterator find_older(rak::timer t);
|
||||||
|
|
||||||
Signal& signal_update() { return m_signalUpdate; }
|
Signal& signal_update() { return m_signalUpdate; }
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,11 @@
|
|||||||
#define RTORRENT_CORE_POLL_MANAGER_H
|
#define RTORRENT_CORE_POLL_MANAGER_H
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <rak/timer.h>
|
||||||
#include <sigc++/signal.h>
|
#include <sigc++/signal.h>
|
||||||
#include <torrent/poll.h>
|
#include <torrent/poll.h>
|
||||||
|
|
||||||
#include "curl_stack.h"
|
#include "curl_stack.h"
|
||||||
#include "utils/timer.h"
|
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
CurlStack* get_http_stack() { return &m_httpStack; }
|
CurlStack* get_http_stack() { return &m_httpStack; }
|
||||||
torrent::Poll* get_torrent_poll() { return m_poll; }
|
torrent::Poll* get_torrent_poll() { return m_poll; }
|
||||||
|
|
||||||
virtual void poll(utils::Timer timeout) = 0;
|
virtual void poll(rak::timer timeout) = 0;
|
||||||
|
|
||||||
// Use a signal, connect checking for input and updating the display.
|
// Use a signal, connect checking for input and updating the display.
|
||||||
Signal& signal_interrupted() { return m_signalInterrupted; }
|
Signal& signal_interrupted() { return m_signalInterrupted; }
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ PollManagerEPoll::~PollManagerEPoll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerEPoll::poll(utils::Timer timeout) {
|
PollManagerEPoll::poll(rak::timer timeout) {
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||||
// resolution.
|
// resolution.
|
||||||
torrent::perform();
|
torrent::perform();
|
||||||
timeout = std::min(timeout, utils::Timer(torrent::next_timeout()));
|
timeout = std::min(timeout, rak::timer(torrent::next_timeout()));
|
||||||
|
|
||||||
if (m_httpStack.is_busy()) {
|
if (m_httpStack.is_busy()) {
|
||||||
// When we're using libcurl we need to use select, but as this is
|
// When we're using libcurl we need to use select, but as this is
|
||||||
@@ -99,7 +99,7 @@ PollManagerEPoll::poll(utils::Timer timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear the timeout since we've already used it in the select call.
|
// Clear the timeout since we've already used it in the select call.
|
||||||
timeout = utils::Timer();
|
timeout = rak::timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes, below is how much code really *should* have been in this
|
// Yes, below is how much code really *should* have been in this
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
torrent::Poll* get_torrent_poll();
|
torrent::Poll* get_torrent_poll();
|
||||||
|
|
||||||
void poll(utils::Timer timeout);
|
void poll(rak::timer timeout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PollManagerEPoll(torrent::Poll* p) : PollManager(p) {}
|
PollManagerEPoll(torrent::Poll* p) : PollManager(p) {}
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ PollManagerSelect::~PollManagerSelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerSelect::poll(utils::Timer timeout) {
|
PollManagerSelect::poll(rak::timer timeout) {
|
||||||
torrent::perform();
|
torrent::perform();
|
||||||
timeout = std::min(timeout, utils::Timer(torrent::next_timeout()));
|
timeout = std::min(timeout, rak::timer(torrent::next_timeout()));
|
||||||
|
|
||||||
#if defined USE_VARIABLE_FDSET
|
#if defined USE_VARIABLE_FDSET
|
||||||
std::memset(m_readSet, 0, m_setSize);
|
std::memset(m_readSet, 0, m_setSize);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
static PollManagerSelect* create(int maxOpenSockets);
|
static PollManagerSelect* create(int maxOpenSockets);
|
||||||
~PollManagerSelect();
|
~PollManagerSelect();
|
||||||
|
|
||||||
void poll(utils::Timer timeout);
|
void poll(rak::timer timeout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PollManagerSelect(torrent::Poll* p) : PollManager(p) {}
|
PollManagerSelect(torrent::Poll* p) : PollManager(p) {}
|
||||||
|
|||||||
@@ -38,10 +38,10 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <rak/functional.h>
|
||||||
#include "rak/functional.h"
|
|
||||||
|
|
||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ void
|
|||||||
Manager::do_update() {
|
Manager::do_update() {
|
||||||
Canvas::refresh_std();
|
Canvas::refresh_std();
|
||||||
|
|
||||||
utils::displayScheduler.execute(utils::Timer::cache());
|
displayScheduler.execute(cachedTime);
|
||||||
std::for_each(begin(), end(), rak::if_then(std::mem_fun(&Window::is_active), std::mem_fun(&Window::refresh)));
|
std::for_each(begin(), end(), rak::if_then(std::mem_fun(&Window::is_active), std::mem_fun(&Window::refresh)));
|
||||||
|
|
||||||
Canvas::do_update();
|
Canvas::do_update();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#include <torrent/tracker.h>
|
#include <torrent/tracker.h>
|
||||||
|
|
||||||
#include "core/download.h"
|
#include "core/download.h"
|
||||||
#include "utils/timer.h"
|
#include <rak/timer.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ Window::Window(Canvas* c, bool d, int h) :
|
|||||||
m_dynamic(d),
|
m_dynamic(d),
|
||||||
m_minHeight(h) {
|
m_minHeight(h) {
|
||||||
|
|
||||||
m_taskUpdate.set_iterator(utils::displayScheduler.end());
|
m_taskUpdate.set_iterator(displayScheduler.end());
|
||||||
m_taskUpdate.set_slot(sigc::mem_fun(*this, &Window::redraw));
|
m_taskUpdate.set_slot(sigc::mem_fun(*this, &Window::redraw));
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
utils::displayScheduler.erase(&m_taskUpdate);
|
displayScheduler.erase(&m_taskUpdate);
|
||||||
delete m_canvas;
|
delete m_canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ Window::set_active(bool a) {
|
|||||||
if (a)
|
if (a)
|
||||||
mark_dirty();
|
mark_dirty();
|
||||||
else
|
else
|
||||||
utils::displayScheduler.erase(&m_taskUpdate);
|
displayScheduler.erase(&m_taskUpdate);
|
||||||
|
|
||||||
m_active = a;
|
m_active = a;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,11 @@
|
|||||||
#ifndef RTORRENT_WINDOW_BASE_H
|
#ifndef RTORRENT_WINDOW_BASE_H
|
||||||
#define RTORRENT_WINDOW_BASE_H
|
#define RTORRENT_WINDOW_BASE_H
|
||||||
|
|
||||||
|
#include <rak/timer.h>
|
||||||
#include <sigc++/slot.h>
|
#include <sigc++/slot.h>
|
||||||
|
|
||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
#include "utils/task.h"
|
#include "globals.h"
|
||||||
#include "utils/timer.h"
|
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
@@ -57,9 +57,9 @@ public:
|
|||||||
|
|
||||||
bool is_active() { return m_active; }
|
bool is_active() { return m_active; }
|
||||||
bool is_dynamic() { return m_dynamic; }
|
bool is_dynamic() { return m_dynamic; }
|
||||||
bool is_dirty() { return utils::displayScheduler.is_scheduled(&m_taskUpdate); }
|
bool is_dirty() { return displayScheduler.is_scheduled(&m_taskUpdate); }
|
||||||
|
|
||||||
//utils::Timer get_next_draw() { return m_nextDraw; }
|
//utils::rak::timer get_next_draw() { return m_nextDraw; }
|
||||||
|
|
||||||
int get_min_height() { return m_minHeight; }
|
int get_min_height() { return m_minHeight; }
|
||||||
|
|
||||||
@@ -92,8 +92,8 @@ protected:
|
|||||||
|
|
||||||
inline void
|
inline void
|
||||||
Window::mark_dirty() {
|
Window::mark_dirty() {
|
||||||
utils::displayScheduler.erase(&m_taskUpdate);
|
displayScheduler.erase(&m_taskUpdate);
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, utils::Timer::cache());
|
displayScheduler.insert(&m_taskUpdate, cachedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,12 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <rak/algorithm.h>
|
||||||
|
|
||||||
#include "core/download.h"
|
#include "core/download.h"
|
||||||
#include "rak/algorithm.h"
|
|
||||||
|
|
||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "window_download_list.h"
|
#include "window_download_list.h"
|
||||||
|
|
||||||
@@ -58,7 +60,7 @@ WindowDownloadList::~WindowDownloadList() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowDownloadList::redraw() {
|
WindowDownloadList::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
|
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <torrent/rate.h>
|
#include <torrent/rate.h>
|
||||||
|
|
||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "window_download_statusbar.h"
|
#include "window_download_statusbar.h"
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowDownloadStatusbar::redraw() {
|
WindowDownloadStatusbar::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
|
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <rak/algorithm.h>
|
||||||
#include <torrent/path.h>
|
#include <torrent/path.h>
|
||||||
|
|
||||||
#include "core/download.h"
|
#include "core/download.h"
|
||||||
#include "rak/algorithm.h"
|
|
||||||
|
|
||||||
#include "window_file_list.h"
|
#include "window_file_list.h"
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ WindowFileList::WindowFileList(core::Download* d, unsigned int* focus) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowFileList::redraw() {
|
WindowFileList::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 10 * 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 10 * 1000000).round_seconds());
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
if (m_download->get_download().size_file_entries() == 0 ||
|
if (m_download->get_download().size_file_entries() == 0 ||
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowHttpQueue::redraw() {
|
WindowHttpQueue::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
|
|
||||||
cleanup_list();
|
cleanup_list();
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ WindowHttpQueue::redraw() {
|
|||||||
void
|
void
|
||||||
WindowHttpQueue::cleanup_list() {
|
WindowHttpQueue::cleanup_list() {
|
||||||
for (Container::iterator itr = m_container.begin(); itr != m_container.end();)
|
for (Container::iterator itr = m_container.begin(); itr != m_container.end();)
|
||||||
if (itr->m_http == NULL && itr->m_timer < utils::Timer::cache())
|
if (itr->m_http == NULL && itr->m_timer < cachedTime)
|
||||||
itr = m_container.erase(itr);
|
itr = m_container.erase(itr);
|
||||||
else
|
else
|
||||||
++itr;
|
++itr;
|
||||||
@@ -147,7 +147,7 @@ WindowHttpQueue::receive_erase(core::CurlGet* h) {
|
|||||||
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
|
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
|
||||||
|
|
||||||
itr->m_http = NULL;
|
itr->m_http = NULL;
|
||||||
itr->m_timer = utils::Timer::cache() + 10000000;
|
itr->m_timer = cachedTime + 10000000;
|
||||||
|
|
||||||
mark_dirty();
|
mark_dirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
|
|
||||||
core::CurlGet* m_http;
|
core::CurlGet* m_http;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
utils::Timer m_timer;
|
rak::timer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<Node> Container;
|
typedef std::list<Node> Container;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ WindowLog::~WindowLog() {
|
|||||||
|
|
||||||
WindowLog::iterator
|
WindowLog::iterator
|
||||||
WindowLog::find_older() {
|
WindowLog::find_older() {
|
||||||
return m_log->find_older(utils::Timer::cache() - 60*1000000);
|
return m_log->find_older(cachedTime - 60*1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ WindowLogComplete::~WindowLogComplete() {
|
|||||||
|
|
||||||
WindowLogComplete::iterator
|
WindowLogComplete::iterator
|
||||||
WindowLogComplete::find_older() {
|
WindowLogComplete::find_older() {
|
||||||
return m_log->find_older(utils::Timer::cache() - 60*1000000);
|
return m_log->find_older(cachedTime - 60*1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f)
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowPeerInfo::redraw() {
|
WindowPeerInfo::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ WindowPeerList::WindowPeerList(core::Download* d, PList* l, PList::iterator* f)
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowPeerList::redraw() {
|
WindowPeerList::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
int x = 2;
|
int x = 2;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ WindowStatusbar::WindowStatusbar(core::Manager* c) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowStatusbar::redraw() {
|
WindowStatusbar::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
|
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ WindowTitle::WindowTitle(const std::string& s) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowTitle::redraw() {
|
WindowTitle::redraw() {
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
m_canvas->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0,
|
m_canvas->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ WindowTrackerList::WindowTrackerList(core::Download* d, unsigned int* focus) :
|
|||||||
void
|
void
|
||||||
WindowTrackerList::redraw() {
|
WindowTrackerList::redraw() {
|
||||||
// TODO: Make this depend on tracker signal.
|
// TODO: Make this depend on tracker signal.
|
||||||
utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 10 * 1000000).round_seconds());
|
displayScheduler.insert(&m_taskUpdate, (cachedTime + 10 * 1000000).round_seconds());
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|||||||
@@ -34,16 +34,10 @@
|
|||||||
// Skomakerveien 33
|
// Skomakerveien 33
|
||||||
// 3185 Skoppum, NORWAY
|
// 3185 Skoppum, NORWAY
|
||||||
|
|
||||||
#ifndef RTORRENT_UTILS_TASK_H
|
#include "config.h"
|
||||||
#define RTORRENT_UTILS_TASK_H
|
|
||||||
|
|
||||||
#include "task_scheduler.h"
|
#include "globals.h"
|
||||||
|
|
||||||
namespace utils {
|
utils::TaskScheduler taskScheduler;
|
||||||
|
utils::TaskScheduler displayScheduler;
|
||||||
extern TaskScheduler taskScheduler;
|
rak::timer cachedTime;
|
||||||
extern TaskScheduler displayScheduler;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// rTorrent - BitTorrent library
|
||||||
|
// Copyright (C) 2005, Jari Sundell
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
// In addition, as a special exception, the copyright holders give
|
||||||
|
// permission to link the code of portions of this program with the
|
||||||
|
// OpenSSL library under certain conditions as described in each
|
||||||
|
// individual source file, and distribute linked combinations
|
||||||
|
// including the two.
|
||||||
|
//
|
||||||
|
// You must obey the GNU General Public License in all respects for
|
||||||
|
// all of the code used other than OpenSSL. If you modify file(s)
|
||||||
|
// with this exception, you may extend this exception to your version
|
||||||
|
// of the file(s), but you are not obligated to do so. If you do not
|
||||||
|
// wish to do so, delete this exception statement from your version.
|
||||||
|
// If you delete this exception statement from all source files in the
|
||||||
|
// program, then also delete it here.
|
||||||
|
//
|
||||||
|
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||||
|
//
|
||||||
|
// Skomakerveien 33
|
||||||
|
// 3185 Skoppum, NORWAY
|
||||||
|
|
||||||
|
#ifndef TORRENT_GLOBALS_H
|
||||||
|
#define TORRENT_GLOBALS_H
|
||||||
|
|
||||||
|
#include <rak/timer.h>
|
||||||
|
|
||||||
|
#include "utils/task_scheduler.h"
|
||||||
|
|
||||||
|
extern utils::TaskScheduler taskScheduler;
|
||||||
|
extern utils::TaskScheduler displayScheduler;
|
||||||
|
extern rak::timer cachedTime;
|
||||||
|
|
||||||
|
#endif
|
||||||
+12
-20
@@ -62,29 +62,21 @@
|
|||||||
#include "display/manager.h"
|
#include "display/manager.h"
|
||||||
#include "input/bindings.h"
|
#include "input/bindings.h"
|
||||||
|
|
||||||
#include "utils/task.h"
|
|
||||||
#include "utils/timer.h"
|
|
||||||
#include "utils/directory.h"
|
#include "utils/directory.h"
|
||||||
|
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "signal_handler.h"
|
#include "signal_handler.h"
|
||||||
#include "option_file.h"
|
#include "option_file.h"
|
||||||
#include "option_handler.h"
|
#include "option_handler.h"
|
||||||
#include "option_handler_rules.h"
|
#include "option_handler_rules.h"
|
||||||
#include "option_parser.h"
|
#include "option_parser.h"
|
||||||
|
|
||||||
int64_t utils::Timer::m_cache;
|
|
||||||
|
|
||||||
uint32_t countTicks = 0;
|
uint32_t countTicks = 0;
|
||||||
|
|
||||||
void do_panic(int signum);
|
void do_panic(int signum);
|
||||||
void print_help();
|
void print_help();
|
||||||
|
|
||||||
namespace utils {
|
|
||||||
TaskScheduler taskScheduler;
|
|
||||||
TaskScheduler displayScheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_resized() {
|
is_resized() {
|
||||||
static int x = 0;
|
static int x = 0;
|
||||||
@@ -185,13 +177,13 @@ load_arg_torrents(Control* c, char** first, char** last) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv) {
|
main(int argc, char** argv) {
|
||||||
utils::Timer::update();
|
cachedTime = rak::timer::current();
|
||||||
|
|
||||||
OptionHandler optionHandler;
|
OptionHandler optionHandler;
|
||||||
Control uiControl;
|
Control uiControl;
|
||||||
|
|
||||||
srandom(utils::Timer::cache().usec());
|
srandom(cachedTime.usec());
|
||||||
srand48(utils::Timer::cache().usec());
|
srand48(cachedTime.usec());
|
||||||
|
|
||||||
initialize_option_handler(&uiControl, &optionHandler);
|
initialize_option_handler(&uiControl, &optionHandler);
|
||||||
|
|
||||||
@@ -223,19 +215,19 @@ main(int argc, char** argv) {
|
|||||||
while (!uiControl.is_shutdown_completed()) {
|
while (!uiControl.is_shutdown_completed()) {
|
||||||
countTicks++;
|
countTicks++;
|
||||||
|
|
||||||
utils::Timer::update();
|
cachedTime = rak::timer::current();
|
||||||
utils::taskScheduler.execute(utils::Timer::cache());
|
taskScheduler.execute(cachedTime);
|
||||||
|
|
||||||
// This needs to be called every second or so. Currently done by
|
// This needs to be called every second or so. Currently done by
|
||||||
// the throttle task in libtorrent.
|
// the throttle task in libtorrent.
|
||||||
if (!utils::displayScheduler.empty() &&
|
if (!displayScheduler.empty() &&
|
||||||
utils::displayScheduler.get_next_timeout() <= utils::Timer::cache())
|
displayScheduler.get_next_timeout() <= cachedTime)
|
||||||
uiControl.display()->do_update();
|
uiControl.display()->do_update();
|
||||||
|
|
||||||
// Do shutdown check before poll, not after.
|
// Do shutdown check before poll, not after.
|
||||||
uiControl.core()->get_poll_manager()->poll(!utils::taskScheduler.empty() ?
|
uiControl.core()->get_poll_manager()->poll(!taskScheduler.empty() ?
|
||||||
utils::taskScheduler.get_next_timeout() - utils::Timer::cache() :
|
taskScheduler.get_next_timeout() - cachedTime :
|
||||||
60 * 1000000);
|
60 * 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiControl.cleanup();
|
uiControl.cleanup();
|
||||||
@@ -288,7 +280,7 @@ do_panic(int signum) {
|
|||||||
void
|
void
|
||||||
receive_tracker_dump(std::istream* s) {
|
receive_tracker_dump(std::istream* s) {
|
||||||
std::stringstream filename;
|
std::stringstream filename;
|
||||||
filename << "./tracker_dump." << utils::Timer::current().seconds();
|
filename << "./tracker_dump." << rak::timer::current().seconds();
|
||||||
|
|
||||||
std::fstream out(filename.str().c_str(), std::ios::out | std::ios::trunc);
|
std::fstream out(filename.str().c_str(), std::ios::out | std::ios::trunc);
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ DownloadList::DownloadList(Control* c) :
|
|||||||
m_uiArray[DISPLAY_LOG] = new ElementLogComplete(&m_control->core()->get_log_complete());
|
m_uiArray[DISPLAY_LOG] = new ElementLogComplete(&m_control->core()->get_log_complete());
|
||||||
m_windowLog = new WLog(&m_control->core()->get_log_important());
|
m_windowLog = new WLog(&m_control->core()->get_log_important());
|
||||||
|
|
||||||
m_taskUpdate.set_iterator(utils::taskScheduler.end());
|
m_taskUpdate.set_iterator(taskScheduler.end());
|
||||||
m_taskUpdate.set_slot(sigc::mem_fun(*this, &DownloadList::task_update)),
|
m_taskUpdate.set_slot(sigc::mem_fun(*this, &DownloadList::task_update)),
|
||||||
|
|
||||||
setup_keys();
|
setup_keys();
|
||||||
@@ -112,7 +112,7 @@ DownloadList::activate() {
|
|||||||
if (is_active())
|
if (is_active())
|
||||||
throw std::logic_error("ui::Download::activate() called on an already activated object");
|
throw std::logic_error("ui::Download::activate() called on an already activated object");
|
||||||
|
|
||||||
utils::taskScheduler.insert(&m_taskUpdate, utils::Timer::cache() + 1000000);
|
taskScheduler.insert(&m_taskUpdate, cachedTime + 1000000);
|
||||||
|
|
||||||
m_windowTextInput->set_active(false);
|
m_windowTextInput->set_active(false);
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ DownloadList::disable() {
|
|||||||
|
|
||||||
disable_display();
|
disable_display();
|
||||||
|
|
||||||
utils::taskScheduler.erase(&m_taskUpdate);
|
taskScheduler.erase(&m_taskUpdate);
|
||||||
|
|
||||||
m_control->display()->erase(m_window);
|
m_control->display()->erase(m_window);
|
||||||
m_control->display()->erase(m_windowTitle);
|
m_control->display()->erase(m_windowTitle);
|
||||||
@@ -304,7 +304,7 @@ void
|
|||||||
DownloadList::task_update() {
|
DownloadList::task_update() {
|
||||||
m_windowLog->receive_update();
|
m_windowLog->receive_update();
|
||||||
|
|
||||||
utils::taskScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds());
|
taskScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -41,9 +41,10 @@
|
|||||||
|
|
||||||
#include "core/download_list.h"
|
#include "core/download_list.h"
|
||||||
#include "display/manager.h"
|
#include "display/manager.h"
|
||||||
#include "utils/task.h"
|
|
||||||
#include "utils/list_focus.h"
|
#include "utils/list_focus.h"
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
class Control;
|
class Control;
|
||||||
|
|
||||||
namespace input {
|
namespace input {
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ libsub_utils_a_SOURCES = \
|
|||||||
list_focus.h \
|
list_focus.h \
|
||||||
parse.cc \
|
parse.cc \
|
||||||
parse.h \
|
parse.h \
|
||||||
task.h \
|
|
||||||
task_item.h \
|
task_item.h \
|
||||||
task_scheduler.cc \
|
task_scheduler.cc \
|
||||||
task_scheduler.h \
|
task_scheduler.h
|
||||||
timer.h
|
|
||||||
|
|
||||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||||
|
|||||||
@@ -38,18 +38,17 @@
|
|||||||
#define RTORRENT_UTILS_TASK_ITEM_H
|
#define RTORRENT_UTILS_TASK_ITEM_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <rak/timer.h>
|
||||||
#include <sigc++/slot.h>
|
#include <sigc++/slot.h>
|
||||||
|
|
||||||
#include "utils/timer.h"
|
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
// The user is responsible for removing TaskItem from the TaskScheduler.
|
// The user is responsible for removing TaskItem from the TaskScheduler.
|
||||||
|
|
||||||
class TaskItem {
|
class TaskItem {
|
||||||
public:
|
public:
|
||||||
typedef sigc::slot<void> Slot;
|
typedef sigc::slot<void> Slot;
|
||||||
typedef std::list<std::pair<Timer, TaskItem*> >::iterator iterator;
|
typedef std::list<std::pair<rak::timer, TaskItem*> >::iterator iterator;
|
||||||
|
|
||||||
TaskItem(Slot s = Slot()) : m_slot(s) {}
|
TaskItem(Slot s = Slot()) : m_slot(s) {}
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ public:
|
|||||||
const iterator get_iterator() const { return m_iterator; }
|
const iterator get_iterator() const { return m_iterator; }
|
||||||
void set_iterator(iterator itr) { m_iterator = itr; }
|
void set_iterator(iterator itr) { m_iterator = itr; }
|
||||||
|
|
||||||
const Timer& get_time() const { return m_iterator->first; }
|
const rak::timer& get_time() const { return m_iterator->first; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TaskItem(const TaskItem& t);
|
TaskItem(const TaskItem& t);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
void
|
void
|
||||||
TaskScheduler::insert(TaskItem* task, Timer time) {
|
TaskScheduler::insert(TaskItem* task, rak::timer time) {
|
||||||
if (is_scheduled(task))
|
if (is_scheduled(task))
|
||||||
throw std::logic_error("TaskScheduler::insert(...) tried to insert an already inserted or invalid TaskItem");
|
throw std::logic_error("TaskScheduler::insert(...) tried to insert an already inserted or invalid TaskItem");
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ TaskScheduler::erase(TaskItem* task) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TaskScheduler::execute(Timer time) {
|
TaskScheduler::execute(rak::timer time) {
|
||||||
m_entry = std::find_if(begin(), end(), rak::less(time, rak::mem_ptr_ref(&value_type::first)));
|
m_entry = std::find_if(begin(), end(), rak::less(time, rak::mem_ptr_ref(&value_type::first)));
|
||||||
|
|
||||||
// Since we are always using the front rather than a splice of the
|
// Since we are always using the front rather than a splice of the
|
||||||
|
|||||||
@@ -41,9 +41,9 @@
|
|||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
class TaskScheduler : private std::list<std::pair<Timer, TaskItem*> > {
|
class TaskScheduler : private std::list<std::pair<rak::timer, TaskItem*> > {
|
||||||
public:
|
public:
|
||||||
typedef std::list<std::pair<Timer, TaskItem*> > Base;
|
typedef std::list<std::pair<rak::timer, TaskItem*> > Base;
|
||||||
|
|
||||||
using Base::value_type;
|
using Base::value_type;
|
||||||
using Base::reference;
|
using Base::reference;
|
||||||
@@ -60,14 +60,14 @@ public:
|
|||||||
|
|
||||||
TaskScheduler() : m_entry(begin()) {}
|
TaskScheduler() : m_entry(begin()) {}
|
||||||
|
|
||||||
void insert(TaskItem* task, Timer time);
|
void insert(TaskItem* task, rak::timer time);
|
||||||
void erase(TaskItem* task);
|
void erase(TaskItem* task);
|
||||||
|
|
||||||
void execute(Timer time);
|
void execute(rak::timer time);
|
||||||
|
|
||||||
bool is_scheduled(const TaskItem* task) const { return task->get_iterator() != end(); }
|
bool is_scheduled(const TaskItem* task) const { return task->get_iterator() != end(); }
|
||||||
|
|
||||||
Timer get_next_timeout() const { return begin()->first; }
|
rak::timer get_next_timeout() const { return begin()->first; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
iterator m_entry;
|
iterator m_entry;
|
||||||
|
|||||||
Reference in New Issue
Block a user