mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-04 21:29:21 +00:00
Moved over to a next time based display update.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@320 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+1
-2
@@ -29,8 +29,7 @@ Poll::poll(utils::Timer timeout) {
|
||||
m_maxFd = std::max(m_maxFd, n);
|
||||
}
|
||||
|
||||
timeout = std::min(timeout, utils::Timer(torrent::get(torrent::TIME_SELECT)));
|
||||
timeval t = timeout.tval();
|
||||
timeval t = std::min(timeout, utils::Timer(torrent::get(torrent::TIME_SELECT))).tval();
|
||||
|
||||
errno = 0;
|
||||
m_maxFd = select(m_maxFd + 1, m_readSet, m_writeSet, m_exceptSet, &t);
|
||||
|
||||
@@ -9,10 +9,10 @@ libsub_display_a_SOURCES = \
|
||||
utils.h \
|
||||
window.cc \
|
||||
window.h \
|
||||
window_download_statusbar.cc \
|
||||
window_download_statusbar.h \
|
||||
window_download_list.cc \
|
||||
window_download_list.h \
|
||||
window_download_statusbar.cc \
|
||||
window_download_statusbar.h \
|
||||
window_http_queue.cc \
|
||||
window_http_queue.h \
|
||||
window_input.cc \
|
||||
|
||||
@@ -56,7 +56,8 @@ void
|
||||
Manager::do_update() {
|
||||
Canvas::refresh_std();
|
||||
|
||||
std::for_each(begin(), end(), func::if_then(std::mem_fun(&Window::is_active), std::mem_fun(&Window::redraw)));
|
||||
std::for_each(begin(), end(), func::if_then(std::mem_fun(&Window::is_active), func::if_then(std::mem_fun(&Window::is_dirty),
|
||||
std::mem_fun(&Window::redraw))));
|
||||
std::for_each(begin(), end(), func::if_then(std::mem_fun(&Window::is_active), std::mem_fun(&Window::refresh)));
|
||||
|
||||
Canvas::do_update();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "canvas.h"
|
||||
#include "window.h"
|
||||
|
||||
namespace display {
|
||||
@@ -13,11 +12,6 @@ Window::~Window() {
|
||||
delete m_canvas;
|
||||
}
|
||||
|
||||
void
|
||||
Window::refresh() {
|
||||
m_canvas->refresh();
|
||||
}
|
||||
|
||||
void
|
||||
Window::resize(int x, int y, int w, int h) {
|
||||
if (x < 0 || y < 0)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <sigc++/slot.h>
|
||||
|
||||
#include "canvas.h"
|
||||
#include "utils/timer.h"
|
||||
|
||||
namespace display {
|
||||
@@ -20,17 +21,19 @@ public:
|
||||
|
||||
bool is_active() { return m_active; }
|
||||
bool is_dynamic() { return m_dynamic; }
|
||||
bool is_dirty() { return m_lastDraw == 0; }
|
||||
bool is_dirty() { return m_nextDraw <= utils::Timer::cache(); }
|
||||
|
||||
utils::Timer get_next_draw() { return m_nextDraw; }
|
||||
|
||||
int get_min_height() { return m_minHeight; }
|
||||
|
||||
bool get_active() { return m_active; }
|
||||
void set_active(bool a) { m_active = a; }
|
||||
|
||||
void refresh();
|
||||
void refresh() { m_canvas->refresh(); }
|
||||
void resize(int x, int y, int w, int h);
|
||||
|
||||
void mark_dirty() { m_lastDraw = 0; }
|
||||
void mark_dirty() { m_nextDraw = utils::Timer::min(); }
|
||||
|
||||
virtual void redraw() = 0;
|
||||
|
||||
@@ -48,7 +51,7 @@ protected:
|
||||
bool m_dynamic;
|
||||
int m_minHeight;
|
||||
|
||||
utils::Timer m_lastDraw;
|
||||
utils::Timer m_nextDraw;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@ WindowDownloadList::WindowDownloadList(DList* l, DList::iterator* f) :
|
||||
|
||||
void
|
||||
WindowDownloadList::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
|
||||
m_canvas->erase();
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) :
|
||||
|
||||
void
|
||||
WindowDownloadStatusbar::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
|
||||
m_canvas->erase();
|
||||
|
||||
|
||||
@@ -22,10 +22,7 @@ WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) :
|
||||
|
||||
void
|
||||
WindowHttpQueue::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
|
||||
cleanup_list();
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ WindowInput::WindowInput(input::TextInput* input) :
|
||||
|
||||
void
|
||||
WindowInput::redraw() {
|
||||
if (!is_dirty())
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::max();
|
||||
m_canvas->erase();
|
||||
|
||||
m_canvas->print(0, 0, "> %s", m_input->c_str());
|
||||
|
||||
@@ -26,10 +26,7 @@ WindowLog::find_older() {
|
||||
|
||||
void
|
||||
WindowLog::redraw() {
|
||||
if (!is_dirty())
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::max();
|
||||
|
||||
m_canvas->erase();
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f)
|
||||
|
||||
void
|
||||
WindowPeerInfo::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
m_canvas->erase();
|
||||
|
||||
int y = 0;
|
||||
|
||||
@@ -15,10 +15,7 @@ WindowPeerList::WindowPeerList(PList* l, PList::iterator* f) :
|
||||
|
||||
void
|
||||
WindowPeerList::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
m_canvas->erase();
|
||||
|
||||
int x = 2;
|
||||
|
||||
@@ -17,20 +17,14 @@ WindowStatusbar::WindowStatusbar(core::Manager* c) :
|
||||
|
||||
void
|
||||
WindowStatusbar::redraw() {
|
||||
m_counter++;
|
||||
|
||||
if (utils::Timer::cache() - m_lastDraw < 10000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
|
||||
m_canvas->erase();
|
||||
m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u",
|
||||
m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i",
|
||||
(int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024,
|
||||
m_core->get_dns().empty() ? "<default>" : m_core->get_dns().c_str(),
|
||||
(int)torrent::get(torrent::LISTEN_PORT),
|
||||
(int)torrent::get(torrent::HANDSHAKES_TOTAL),
|
||||
m_counter);
|
||||
(int)torrent::get(torrent::HANDSHAKES_TOTAL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ WindowTitle::WindowTitle(const std::string& s) :
|
||||
|
||||
void
|
||||
WindowTitle::redraw() {
|
||||
if (utils::Timer::cache() - m_lastDraw < 10000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = utils::Timer::cache();
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 1000000;
|
||||
m_canvas->erase();
|
||||
|
||||
m_canvas->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0,
|
||||
|
||||
@@ -159,6 +159,8 @@ main(int argc, char** argv) {
|
||||
utils::Timer::update();
|
||||
utils::TaskSchedule::perform(utils::Timer::cache());
|
||||
|
||||
// This needs to be called every second or so. Currently done by
|
||||
// the throttle task in libtorrent.
|
||||
uiControl.get_display().do_update();
|
||||
|
||||
uiControl.get_core().get_poll().poll(utils::TaskSchedule::get_timeout());
|
||||
|
||||
+23
-18
@@ -1,6 +1,7 @@
|
||||
#ifndef LIBTORRENT_TIMER_H
|
||||
#define LIBTORRENT_TIMER_H
|
||||
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
@@ -13,18 +14,10 @@ class Timer {
|
||||
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) {}
|
||||
|
||||
int64_t usec() const { return m_time; }
|
||||
int64_t usec() const { return m_time; }
|
||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||
|
||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||
|
||||
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); }
|
||||
|
||||
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; }
|
||||
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
|
||||
|
||||
static Timer current() {
|
||||
timeval t;
|
||||
@@ -38,15 +31,27 @@ class Timer {
|
||||
|
||||
// TODO: Find out if it's worth it. The kernel is supposed to cache the
|
||||
// time. Though system calls would be more expensive than we can afford.
|
||||
static Timer cache() { return Timer(m_cache); }
|
||||
static Timer cache() { return Timer(m_cache); }
|
||||
|
||||
static void update() { m_cache = Timer::current().usec(); }
|
||||
static Timer min() { return 0; }
|
||||
static Timer max() { return (int64_t)std::numeric_limits<time_t>::max() * 1000000; }
|
||||
|
||||
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; }
|
||||
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); }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
bool operator == (const Timer& t) const { return m_time == t.m_time; }
|
||||
|
||||
private:
|
||||
int64_t m_time;
|
||||
|
||||
Reference in New Issue
Block a user