From 32a3619cd86cfc0d0a8481930f0088fff07a72f1 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 4 Dec 2005 21:08:17 +0000 Subject: [PATCH] * 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 --- Makefile.am | 1 + rak/algorithm.h | 4 +- {src/utils => rak}/timer.h | 57 +++++++++++------------- src/Makefile.am | 2 + src/control.cc | 8 ++-- src/control.h | 2 +- src/core/download_factory.cc | 14 +++--- src/core/log.cc | 9 ++-- src/core/log.h | 8 ++-- src/core/poll_manager.h | 4 +- src/core/poll_manager_epoll.cc | 6 +-- src/core/poll_manager_epoll.h | 2 +- src/core/poll_manager_select.cc | 4 +- src/core/poll_manager_select.h | 2 +- src/display/manager.cc | 6 +-- src/display/utils.cc | 2 +- src/display/window.cc | 6 +-- src/display/window.h | 12 ++--- src/display/window_download_list.cc | 6 ++- src/display/window_download_statusbar.cc | 3 +- src/display/window_file_list.cc | 4 +- src/display/window_http_queue.cc | 6 +-- src/display/window_http_queue.h | 2 +- src/display/window_log.cc | 2 +- src/display/window_log_complete.cc | 2 +- src/display/window_peer_info.cc | 2 +- src/display/window_peer_list.cc | 2 +- src/display/window_statusbar.cc | 2 +- src/display/window_title.cc | 2 +- src/display/window_tracker_list.cc | 2 +- src/{utils/task.h => globals.cc} | 16 +++---- src/globals.h | 48 ++++++++++++++++++++ src/main.cc | 32 +++++-------- src/ui/download_list.cc | 8 ++-- src/ui/download_list.h | 3 +- src/utils/Makefile.am | 4 +- src/utils/task_item.h | 9 ++-- src/utils/task_scheduler.cc | 4 +- src/utils/task_scheduler.h | 10 ++--- 39 files changed, 175 insertions(+), 143 deletions(-) rename {src/utils => rak}/timer.h (61%) rename src/{utils/task.h => globals.cc} (89%) create mode 100644 src/globals.h diff --git a/Makefile.am b/Makefile.am index a37aa7bf..7364aa5e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,7 @@ EXTRA_DIST= \ rak/error_number.h \ rak/functional.h \ rak/string_manip.h \ + rak/timer.h \ rak/unordered_vector.h \ scripts/checks.m4 \ scripts/common.m4 diff --git a/rak/algorithm.h b/rak/algorithm.h index 341e2904..2b6b521e 100644 --- a/rak/algorithm.h +++ b/rak/algorithm.h @@ -38,6 +38,7 @@ #define RAK_ALGORITHM_H #include +#include namespace rak { @@ -90,8 +91,7 @@ advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __las } template -struct -compare_base : public std::binary_function<_Value, _Value, bool> { +struct compare_base : public std::binary_function<_Value, _Value, bool> { bool operator () (const _Value& complete, const _Value& base) const { return !complete.compare(0, base.size(), base); } diff --git a/src/utils/timer.h b/rak/timer.h similarity index 61% rename from src/utils/timer.h rename to rak/timer.h index 6e70f33b..09cb0a9a 100644 --- a/src/utils/timer.h +++ b/rak/timer.h @@ -1,4 +1,4 @@ -// rTorrent - BitTorrent client +// libTorrent - BitTorrent library // Copyright (C) 2005, Jari Sundell // // This program is free software; you can redistribute it and/or modify @@ -34,63 +34,56 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_TIMER_H -#define RTORRENT_UTILS_TIMER_H +#ifndef RAK_TIMER_H +#define RAK_TIMER_H #include #include -namespace utils { +namespace rak { // Don't convert negative Timer to timeval and then back to Timer, that will bork. -class Timer { +class timer { public: - Timer() : m_time(0) {} - 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() : m_time(0) {} + 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) {} int32_t seconds() const { return m_time / 1000000; } 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}; } - static Timer current(); + static timer current(); - // Cached time, updated in the beginning of torrent::work call. - // Don't use outside socket_base read/write/except or Service::service. - 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; } + 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; } - 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; } + timer operator -= (int64_t t) { m_time -= t; return *this; } + timer operator -= (const timer& t) { m_time -= t.m_time; return *this; } - 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 operator += (int64_t t) { m_time += t; return *this; } + timer operator += (const timer& t) { m_time += t.m_time; return *this; } private: int64_t m_time; - - // Instantiated in torrent.cc - static int64_t m_cache; }; -inline Timer -Timer::current() { +inline timer +timer::current() { timeval t; gettimeofday(&t, 0); - return Timer(t); + return timer(t); } } diff --git a/src/Makefile.am b/src/Makefile.am index 0b63731f..7866baab 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,8 @@ rtorrent_LDADD = \ rtorrent_SOURCES = \ control.cc \ control.h \ + globals.cc \ + globals.h \ main.cc \ option_file.cc \ option_file.h \ diff --git a/src/control.cc b/src/control.cc index ba688b07..b5a65b90 100644 --- a/src/control.cc +++ b/src/control.cc @@ -59,7 +59,7 @@ Control::Control() : 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)); } @@ -90,7 +90,7 @@ Control::initialize() { void Control::cleanup() { - utils::taskScheduler.erase(&m_taskShutdown); + taskScheduler.erase(&m_taskShutdown); m_inputStdin->remove(m_core->get_poll_manager()->get_torrent_poll()); @@ -113,8 +113,8 @@ Control::receive_shutdown() { m_core->shutdown(false); m_shutdownReceived = true; - if (!utils::taskScheduler.is_scheduled(&m_taskShutdown)) - utils::taskScheduler.insert(&m_taskShutdown, utils::Timer::cache() + 5 * 1000000); + if (!taskScheduler.is_scheduled(&m_taskShutdown)) + taskScheduler.insert(&m_taskShutdown, cachedTime + 5 * 1000000); } else { m_core->shutdown(true); diff --git a/src/control.h b/src/control.h index e7ff082f..d12803a6 100644 --- a/src/control.h +++ b/src/control.h @@ -39,7 +39,7 @@ #include -#include "utils/task.h" +#include "globals.h" namespace ui { class Root; diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 32c71df8..14511bd8 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -41,9 +41,9 @@ #include #include -#include "utils/task.h" #include "curl_get.h" #include "http_queue.h" +#include "globals.h" #include "manager.h" #include "download_factory.h" @@ -60,16 +60,16 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) : m_session(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_taskCommit.set_iterator(utils::taskScheduler.end()); + m_taskCommit.set_iterator(taskScheduler.end()); m_taskCommit.set_slot(sigc::mem_fun(*this, &DownloadFactory::receive_commit)); } DownloadFactory::~DownloadFactory() { - utils::taskScheduler.erase(&m_taskLoad); - utils::taskScheduler.erase(&m_taskCommit); + taskScheduler.erase(&m_taskLoad); + taskScheduler.erase(&m_taskCommit); delete m_stream; m_stream = NULL; @@ -77,12 +77,12 @@ DownloadFactory::~DownloadFactory() { void DownloadFactory::load() { - utils::taskScheduler.insert(&m_taskLoad, utils::Timer::cache()); + taskScheduler.insert(&m_taskLoad, cachedTime); } void DownloadFactory::commit() { - utils::taskScheduler.insert(&m_taskCommit, utils::Timer::cache()); + taskScheduler.insert(&m_taskCommit, cachedTime); } void diff --git a/src/core/log.cc b/src/core/log.cc index a0a68050..fe7d10ee 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -37,15 +37,16 @@ #include "config.h" #include +#include +#include "globals.h" #include "log.h" -#include "rak/functional.h" namespace core { void Log::push_front(const std::string& msg) { - Base::push_front(Type(utils::Timer::cache(), msg)); + Base::push_front(Type(cachedTime, msg)); if (size() > 50) Base::pop_back(); @@ -54,8 +55,8 @@ Log::push_front(const std::string& msg) { } Log::iterator -Log::find_older(utils::Timer t) { - return std::find_if(begin(), end(), rak::on(rak::mem_ptr_ref(&Type::first), std::bind2nd(std::less_equal(), 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(), t))); } } diff --git a/src/core/log.h b/src/core/log.h index ec4ce282..63442dc0 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -41,13 +41,13 @@ #include #include -#include "utils/timer.h" +#include namespace core { -class Log : private std::deque > { +class Log : private std::deque > { public: - typedef std::pair Type; + typedef std::pair Type; typedef std::deque Base; typedef sigc::signal0 Signal; @@ -66,7 +66,7 @@ public: 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; } diff --git a/src/core/poll_manager.h b/src/core/poll_manager.h index b14d3858..4749f7b8 100644 --- a/src/core/poll_manager.h +++ b/src/core/poll_manager.h @@ -38,11 +38,11 @@ #define RTORRENT_CORE_POLL_MANAGER_H #include +#include #include #include #include "curl_stack.h" -#include "utils/timer.h" namespace core { @@ -61,7 +61,7 @@ public: CurlStack* get_http_stack() { return &m_httpStack; } 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. Signal& signal_interrupted() { return m_signalInterrupted; } diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc index 8c7f7286..b964008e 100644 --- a/src/core/poll_manager_epoll.cc +++ b/src/core/poll_manager_epoll.cc @@ -61,11 +61,11 @@ PollManagerEPoll::~PollManagerEPoll() { } 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 // resolution. 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()) { // 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. - timeout = utils::Timer(); + timeout = rak::timer(); } // Yes, below is how much code really *should* have been in this diff --git a/src/core/poll_manager_epoll.h b/src/core/poll_manager_epoll.h index 38659d71..a5527001 100644 --- a/src/core/poll_manager_epoll.h +++ b/src/core/poll_manager_epoll.h @@ -52,7 +52,7 @@ public: torrent::Poll* get_torrent_poll(); - void poll(utils::Timer timeout); + void poll(rak::timer timeout); private: PollManagerEPoll(torrent::Poll* p) : PollManager(p) {} diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc index 4122eb6e..988d07ac 100644 --- a/src/core/poll_manager_select.cc +++ b/src/core/poll_manager_select.cc @@ -61,9 +61,9 @@ PollManagerSelect::~PollManagerSelect() { } void -PollManagerSelect::poll(utils::Timer timeout) { +PollManagerSelect::poll(rak::timer timeout) { 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 std::memset(m_readSet, 0, m_setSize); diff --git a/src/core/poll_manager_select.h b/src/core/poll_manager_select.h index 40cab89c..794d68a9 100644 --- a/src/core/poll_manager_select.h +++ b/src/core/poll_manager_select.h @@ -50,7 +50,7 @@ public: static PollManagerSelect* create(int maxOpenSockets); ~PollManagerSelect(); - void poll(utils::Timer timeout); + void poll(rak::timer timeout); private: PollManagerSelect(torrent::Poll* p) : PollManager(p) {} diff --git a/src/display/manager.cc b/src/display/manager.cc index 81e4c078..c4e8f6e8 100644 --- a/src/display/manager.cc +++ b/src/display/manager.cc @@ -38,10 +38,10 @@ #include #include - -#include "rak/functional.h" +#include #include "canvas.h" +#include "globals.h" #include "manager.h" #include "window.h" @@ -98,7 +98,7 @@ void Manager::do_update() { 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))); Canvas::do_update(); diff --git a/src/display/utils.cc b/src/display/utils.cc index 78edbbf0..70d2c449 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -43,7 +43,7 @@ #include #include "core/download.h" -#include "utils/timer.h" +#include #include "utils.h" diff --git a/src/display/window.cc b/src/display/window.cc index ac8256df..d8fbd3a2 100644 --- a/src/display/window.cc +++ b/src/display/window.cc @@ -50,12 +50,12 @@ Window::Window(Canvas* c, bool d, int h) : m_dynamic(d), 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)); } Window::~Window() { - utils::displayScheduler.erase(&m_taskUpdate); + displayScheduler.erase(&m_taskUpdate); delete m_canvas; } @@ -64,7 +64,7 @@ Window::set_active(bool a) { if (a) mark_dirty(); else - utils::displayScheduler.erase(&m_taskUpdate); + displayScheduler.erase(&m_taskUpdate); m_active = a; } diff --git a/src/display/window.h b/src/display/window.h index f89820d1..7cf59ba1 100644 --- a/src/display/window.h +++ b/src/display/window.h @@ -37,11 +37,11 @@ #ifndef RTORRENT_WINDOW_BASE_H #define RTORRENT_WINDOW_BASE_H +#include #include #include "canvas.h" -#include "utils/task.h" -#include "utils/timer.h" +#include "globals.h" namespace display { @@ -57,9 +57,9 @@ public: bool is_active() { return m_active; } 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; } @@ -92,8 +92,8 @@ protected: inline void Window::mark_dirty() { - utils::displayScheduler.erase(&m_taskUpdate); - utils::displayScheduler.insert(&m_taskUpdate, utils::Timer::cache()); + displayScheduler.erase(&m_taskUpdate); + displayScheduler.insert(&m_taskUpdate, cachedTime); } } diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index 512fab8b..a5d66f10 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -36,10 +36,12 @@ #include "config.h" +#include + #include "core/download.h" -#include "rak/algorithm.h" #include "canvas.h" +#include "globals.h" #include "utils.h" #include "window_download_list.h" @@ -58,7 +60,7 @@ WindowDownloadList::~WindowDownloadList() { void WindowDownloadList::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); m_canvas->erase(); diff --git a/src/display/window_download_statusbar.cc b/src/display/window_download_statusbar.cc index 33c99e0e..dd960d4d 100644 --- a/src/display/window_download_statusbar.cc +++ b/src/display/window_download_statusbar.cc @@ -39,6 +39,7 @@ #include #include "canvas.h" +#include "globals.h" #include "utils.h" #include "window_download_statusbar.h" @@ -53,7 +54,7 @@ WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) : void WindowDownloadStatusbar::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); m_canvas->erase(); diff --git a/src/display/window_file_list.cc b/src/display/window_file_list.cc index 9eb94538..a3062790 100644 --- a/src/display/window_file_list.cc +++ b/src/display/window_file_list.cc @@ -37,10 +37,10 @@ #include "config.h" #include +#include #include #include "core/download.h" -#include "rak/algorithm.h" #include "window_file_list.h" @@ -54,7 +54,7 @@ WindowFileList::WindowFileList(core::Download* d, unsigned int* focus) : void 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(); if (m_download->get_download().size_file_entries() == 0 || diff --git a/src/display/window_http_queue.cc b/src/display/window_http_queue.cc index 570e7de1..7458ac30 100644 --- a/src/display/window_http_queue.cc +++ b/src/display/window_http_queue.cc @@ -58,7 +58,7 @@ WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) : void WindowHttpQueue::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); cleanup_list(); @@ -95,7 +95,7 @@ WindowHttpQueue::redraw() { void WindowHttpQueue::cleanup_list() { 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); else ++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"); itr->m_http = NULL; - itr->m_timer = utils::Timer::cache() + 10000000; + itr->m_timer = cachedTime + 10000000; mark_dirty(); } diff --git a/src/display/window_http_queue.h b/src/display/window_http_queue.h index 56ee484c..61dcec9d 100644 --- a/src/display/window_http_queue.h +++ b/src/display/window_http_queue.h @@ -63,7 +63,7 @@ private: core::CurlGet* m_http; std::string m_name; - utils::Timer m_timer; + rak::timer m_timer; }; typedef std::list Container; diff --git a/src/display/window_log.cc b/src/display/window_log.cc index cdd9f383..55ea3724 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -60,7 +60,7 @@ WindowLog::~WindowLog() { WindowLog::iterator WindowLog::find_older() { - return m_log->find_older(utils::Timer::cache() - 60*1000000); + return m_log->find_older(cachedTime - 60*1000000); } void diff --git a/src/display/window_log_complete.cc b/src/display/window_log_complete.cc index df8482cb..1473e3c1 100644 --- a/src/display/window_log_complete.cc +++ b/src/display/window_log_complete.cc @@ -58,7 +58,7 @@ WindowLogComplete::~WindowLogComplete() { WindowLogComplete::iterator WindowLogComplete::find_older() { - return m_log->find_older(utils::Timer::cache() - 60*1000000); + return m_log->find_older(cachedTime - 60*1000000); } void diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index a3f7b5d6..7510045d 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -57,7 +57,7 @@ WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f) void WindowPeerInfo::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); m_canvas->erase(); int y = 0; diff --git a/src/display/window_peer_list.cc b/src/display/window_peer_list.cc index 9a92f337..2d294af6 100644 --- a/src/display/window_peer_list.cc +++ b/src/display/window_peer_list.cc @@ -56,7 +56,7 @@ WindowPeerList::WindowPeerList(core::Download* d, PList* l, PList::iterator* f) void WindowPeerList::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); m_canvas->erase(); int x = 2; diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 3ae6237c..bf12d04b 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -56,7 +56,7 @@ WindowStatusbar::WindowStatusbar(core::Manager* c) : void WindowStatusbar::redraw() { - utils::displayScheduler.insert(&m_taskUpdate, (utils::Timer::cache() + 1000000).round_seconds()); + displayScheduler.insert(&m_taskUpdate, (cachedTime + 1000000).round_seconds()); m_canvas->erase(); diff --git a/src/display/window_title.cc b/src/display/window_title.cc index b7af5fb2..ab8b979f 100644 --- a/src/display/window_title.cc +++ b/src/display/window_title.cc @@ -48,7 +48,7 @@ WindowTitle::WindowTitle(const std::string& s) : void 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->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0, diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc index 2226e252..3a4ffb17 100644 --- a/src/display/window_tracker_list.cc +++ b/src/display/window_tracker_list.cc @@ -55,7 +55,7 @@ WindowTrackerList::WindowTrackerList(core::Download* d, unsigned int* focus) : void WindowTrackerList::redraw() { // 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(); int pos = 0; diff --git a/src/utils/task.h b/src/globals.cc similarity index 89% rename from src/utils/task.h rename to src/globals.cc index a6ab6b51..e1fa2007 100644 --- a/src/utils/task.h +++ b/src/globals.cc @@ -34,16 +34,10 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_TASK_H -#define RTORRENT_UTILS_TASK_H +#include "config.h" -#include "task_scheduler.h" +#include "globals.h" -namespace utils { - -extern TaskScheduler taskScheduler; -extern TaskScheduler displayScheduler; - -} - -#endif +utils::TaskScheduler taskScheduler; +utils::TaskScheduler displayScheduler; +rak::timer cachedTime; diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 00000000..52fe937d --- /dev/null +++ b/src/globals.h @@ -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 +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#ifndef TORRENT_GLOBALS_H +#define TORRENT_GLOBALS_H + +#include + +#include "utils/task_scheduler.h" + +extern utils::TaskScheduler taskScheduler; +extern utils::TaskScheduler displayScheduler; +extern rak::timer cachedTime; + +#endif diff --git a/src/main.cc b/src/main.cc index 9061bb9c..43672f09 100644 --- a/src/main.cc +++ b/src/main.cc @@ -62,29 +62,21 @@ #include "display/manager.h" #include "input/bindings.h" -#include "utils/task.h" -#include "utils/timer.h" #include "utils/directory.h" #include "control.h" +#include "globals.h" #include "signal_handler.h" #include "option_file.h" #include "option_handler.h" #include "option_handler_rules.h" #include "option_parser.h" -int64_t utils::Timer::m_cache; - uint32_t countTicks = 0; void do_panic(int signum); void print_help(); -namespace utils { - TaskScheduler taskScheduler; - TaskScheduler displayScheduler; -} - bool is_resized() { static int x = 0; @@ -185,13 +177,13 @@ load_arg_torrents(Control* c, char** first, char** last) { int main(int argc, char** argv) { - utils::Timer::update(); + cachedTime = rak::timer::current(); OptionHandler optionHandler; Control uiControl; - srandom(utils::Timer::cache().usec()); - srand48(utils::Timer::cache().usec()); + srandom(cachedTime.usec()); + srand48(cachedTime.usec()); initialize_option_handler(&uiControl, &optionHandler); @@ -223,19 +215,19 @@ main(int argc, char** argv) { while (!uiControl.is_shutdown_completed()) { countTicks++; - utils::Timer::update(); - utils::taskScheduler.execute(utils::Timer::cache()); + cachedTime = rak::timer::current(); + taskScheduler.execute(cachedTime); // This needs to be called every second or so. Currently done by // the throttle task in libtorrent. - if (!utils::displayScheduler.empty() && - utils::displayScheduler.get_next_timeout() <= utils::Timer::cache()) + if (!displayScheduler.empty() && + displayScheduler.get_next_timeout() <= cachedTime) uiControl.display()->do_update(); // Do shutdown check before poll, not after. - uiControl.core()->get_poll_manager()->poll(!utils::taskScheduler.empty() ? - utils::taskScheduler.get_next_timeout() - utils::Timer::cache() : - 60 * 1000000); + uiControl.core()->get_poll_manager()->poll(!taskScheduler.empty() ? + taskScheduler.get_next_timeout() - cachedTime : + 60 * 1000000); } uiControl.cleanup(); @@ -288,7 +280,7 @@ do_panic(int signum) { void receive_tracker_dump(std::istream* s) { 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); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 5ba8cd47..fde6ecce 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -85,7 +85,7 @@ DownloadList::DownloadList(Control* c) : m_uiArray[DISPLAY_LOG] = new ElementLogComplete(&m_control->core()->get_log_complete()); 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)), setup_keys(); @@ -112,7 +112,7 @@ DownloadList::activate() { if (is_active()) 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); @@ -139,7 +139,7 @@ DownloadList::disable() { disable_display(); - utils::taskScheduler.erase(&m_taskUpdate); + taskScheduler.erase(&m_taskUpdate); m_control->display()->erase(m_window); m_control->display()->erase(m_windowTitle); @@ -304,7 +304,7 @@ void DownloadList::task_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 diff --git a/src/ui/download_list.h b/src/ui/download_list.h index bf51dad8..a650827f 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -41,9 +41,10 @@ #include "core/download_list.h" #include "display/manager.h" -#include "utils/task.h" #include "utils/list_focus.h" +#include "globals.h" + class Control; namespace input { diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 978de3c0..c750558f 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -8,10 +8,8 @@ libsub_utils_a_SOURCES = \ list_focus.h \ parse.cc \ parse.h \ - task.h \ task_item.h \ task_scheduler.cc \ - task_scheduler.h \ - timer.h + task_scheduler.h INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/utils/task_item.h b/src/utils/task_item.h index 7b06ea70..a32868a8 100644 --- a/src/utils/task_item.h +++ b/src/utils/task_item.h @@ -38,18 +38,17 @@ #define RTORRENT_UTILS_TASK_ITEM_H #include +#include #include -#include "utils/timer.h" - namespace utils { // The user is responsible for removing TaskItem from the TaskScheduler. class TaskItem { public: - typedef sigc::slot Slot; - typedef std::list >::iterator iterator; + typedef sigc::slot Slot; + typedef std::list >::iterator iterator; TaskItem(Slot s = Slot()) : m_slot(s) {} @@ -60,7 +59,7 @@ public: const iterator get_iterator() const { return m_iterator; } 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: TaskItem(const TaskItem& t); diff --git a/src/utils/task_scheduler.cc b/src/utils/task_scheduler.cc index 217a150b..9e0fd643 100644 --- a/src/utils/task_scheduler.cc +++ b/src/utils/task_scheduler.cc @@ -44,7 +44,7 @@ namespace utils { void -TaskScheduler::insert(TaskItem* task, Timer time) { +TaskScheduler::insert(TaskItem* task, rak::timer time) { if (is_scheduled(task)) throw std::logic_error("TaskScheduler::insert(...) tried to insert an already inserted or invalid TaskItem"); @@ -74,7 +74,7 @@ TaskScheduler::erase(TaskItem* task) { } 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))); // Since we are always using the front rather than a splice of the diff --git a/src/utils/task_scheduler.h b/src/utils/task_scheduler.h index f74ab4a7..7dc178c3 100644 --- a/src/utils/task_scheduler.h +++ b/src/utils/task_scheduler.h @@ -41,9 +41,9 @@ namespace utils { -class TaskScheduler : private std::list > { +class TaskScheduler : private std::list > { public: - typedef std::list > Base; + typedef std::list > Base; using Base::value_type; using Base::reference; @@ -60,14 +60,14 @@ public: TaskScheduler() : m_entry(begin()) {} - void insert(TaskItem* task, Timer time); + void insert(TaskItem* task, rak::timer time); 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(); } - Timer get_next_timeout() const { return begin()->first; } + rak::timer get_next_timeout() const { return begin()->first; } private: iterator m_entry;