From 5ad2eff8c9aae490f1bf0fd0b0a73efeff1a02ba Mon Sep 17 00:00:00 2001 From: rakshasa Date: Wed, 30 Dec 2009 07:27:43 +0000 Subject: [PATCH] * Allow interrupting a thread's polling through SIGUSR1. Used to signal events across threads. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1121 e378c898-3ddf-0310-93e7-cc216c733640 --- src/main.cc | 6 ++++++ src/thread_base.cc | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.cc b/src/main.cc index 6e2ab348..6f07f706 100644 --- a/src/main.cc +++ b/src/main.cc @@ -76,6 +76,8 @@ void do_panic(int signum); void print_help(); void initialize_commands(); +void do_nothing() {} + int parse_options(Control* c, int argc, char** argv) { try { @@ -174,6 +176,10 @@ main(int argc, char** argv) { SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); SignalHandler::set_handler(SIGFPE, sigc::bind(sigc::ptr_fun(&do_panic), SIGFPE)); + // SIGUSR1 is used for interrupting polling, forcing that thread + // to process new non-socket events. + SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing)); + torrent::initialize(main_thread->poll()); // Initialize option handlers after libtorrent to ensure diff --git a/src/thread_base.cc b/src/thread_base.cc index c3252d2e..fc4ba7ab 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include "globals.h" @@ -135,7 +137,7 @@ ThreadBase::stop_thread(ThreadBase* thread) { inline rak::timer ThreadBase::client_next_timeout() { if (m_taskScheduler.empty()) - return rak::timer::from_seconds(2); + return rak::timer::from_seconds(600); else if (m_taskScheduler.top()->time() <= cachedTime) return 0; else @@ -189,7 +191,5 @@ ThreadBase::call_queued_items() { void ThreadBase::queue_item(thread_base_func newFunc) { m_threadQueue->push_back(newFunc); - - // TODO: Need to send a signal that interrupts polling so as to - // ensure we react immediately. + pthread_kill(m_thread, SIGUSR1); }