From 1a68177ecac2e647be2ebfdbf80816c6d6d155cc Mon Sep 17 00:00:00 2001 From: rakshasa Date: Mon, 31 Oct 2005 15:40:50 +0000 Subject: [PATCH] * More fiddling of the throttle code. * Fixed a bug that caused idle looping due to epoll_wait timeout using msecs rather than usecs resolution. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@590 e378c898-3ddf-0310-93e7-cc216c733640 --- src/core/download_store.cc | 2 +- src/core/poll_manager_epoll.cc | 8 +++++--- src/core/poll_manager_select.cc | 2 +- src/display/window_statusbar.cc | 8 +++++++- src/input/input_event.cc | 4 ++-- src/main.cc | 4 ++++ src/utils/task_scheduler.cc | 2 +- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/download_store.cc b/src/core/download_store.cc index a0bd5e05..720154e6 100644 --- a/src/core/download_store.cc +++ b/src/core/download_store.cc @@ -53,7 +53,7 @@ void DownloadStore::use(const std::string& path) { m_path = path; - if (*m_path.rbegin() != '/') + if (!m_path.empty() && *m_path.rbegin() != '/') m_path += '/'; } diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc index fbc9d286..7dd1820b 100644 --- a/src/core/poll_manager_epoll.cc +++ b/src/core/poll_manager_epoll.cc @@ -62,6 +62,9 @@ PollManagerEPoll::~PollManagerEPoll() { void PollManagerEPoll::poll(utils::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::get_next_timeout())); if (m_httpStack.is_busy()) { @@ -101,13 +104,12 @@ PollManagerEPoll::poll(utils::Timer timeout) { // Yes, below is how much code really *should* have been in this // function. ;) - torrent::perform(); - if (static_cast(m_poll)->poll(timeout.usec() / 1000) == -1) + if (static_cast(m_poll)->poll((timeout.usec() + 999) / 1000) == -1) return check_error(); - static_cast(m_poll)->perform(); torrent::perform(); + static_cast(m_poll)->perform(); } } diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc index 63c676e1..042fccff 100644 --- a/src/core/poll_manager_select.cc +++ b/src/core/poll_manager_select.cc @@ -62,6 +62,7 @@ PollManagerSelect::~PollManagerSelect() { void PollManagerSelect::poll(utils::Timer timeout) { + torrent::perform(); timeout = std::min(timeout, utils::Timer(torrent::get_next_timeout())); #if defined USE_VARIABLE_FDSET @@ -89,7 +90,6 @@ PollManagerSelect::poll(utils::Timer timeout) { torrent::perform(); static_cast(m_poll)->perform(m_readSet, m_writeSet, m_errorSet); - torrent::perform(); } } diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index cd98816d..42d9624d 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -44,6 +44,8 @@ #include "canvas.h" #include "window_statusbar.h" +extern uint32_t countTicks; + namespace display { WindowStatusbar::WindowStatusbar(core::Manager* c) : @@ -80,7 +82,9 @@ WindowStatusbar::redraw() { (int)torrent::get_listen_port(), !torrent::get_bind_address().empty() ? (" Bind: " + torrent::get_bind_address()).c_str() : ""); - pos = snprintf(buf, 128, "[U %i/%i][S %i/%i/%i][F %i/%i]", +// pos = snprintf(buf, 128, "[U %i/%i][S %i/%i/%i][F %i/%i]", + pos = snprintf(buf, 128, "%i [U %i/%i][S %i/%i/%i][F %i/%i]", + countTicks, torrent::currently_unchoked(), torrent::max_unchoked(), torrent::get_total_handshakes(), @@ -89,6 +93,8 @@ WindowStatusbar::redraw() { torrent::get_open_files(), torrent::get_max_open_files()); + countTicks = 0; + m_canvas->print(m_canvas->get_width() - pos, 0, "%s", buf); } diff --git a/src/input/input_event.cc b/src/input/input_event.cc index c25d601f..ba93570d 100644 --- a/src/input/input_event.cc +++ b/src/input/input_event.cc @@ -56,9 +56,9 @@ InputEvent::remove(torrent::Poll* p) { void InputEvent::event_read() { - int c = getch(); + int c; - if (c != ERR) + while ((c = getch()) != ERR) m_slotPressed(c); } diff --git a/src/main.cc b/src/main.cc index 814daf74..d9174b91 100644 --- a/src/main.cc +++ b/src/main.cc @@ -75,6 +75,8 @@ int64_t utils::Timer::m_cache; +uint32_t countTicks = 0; + void do_panic(int signum); void print_help(); @@ -226,6 +228,8 @@ main(int argc, char** argv) { uiControl.display()->adjust_layout(); while (!uiControl.is_shutdown_completed()) { + countTicks++; + utils::Timer::update(); utils::taskScheduler.execute(utils::Timer::cache()); diff --git a/src/utils/task_scheduler.cc b/src/utils/task_scheduler.cc index 122410d8..217a150b 100644 --- a/src/utils/task_scheduler.cc +++ b/src/utils/task_scheduler.cc @@ -75,7 +75,7 @@ TaskScheduler::erase(TaskItem* task) { void TaskScheduler::execute(Timer time) { - m_entry = std::find_if(begin(), end(), rak::less_equal(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 // due tasks, it is safe to erase them from within other tasks.