From 3b2a47a6d08dbb17ddd92d21b0b98c87297d0d7e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 3 Mar 2013 05:00:31 +0900 Subject: [PATCH] Use thread_base::interrupt for all SIGUSR1 interrupt signals and don't set a handler if it's not supported. --- src/main.cc | 12 +++++++++--- src/thread_base.cc | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.cc b/src/main.cc index 843037f6..5221581a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -202,9 +202,15 @@ main(int argc, char** argv) { SignalHandler::set_sigaction_handler(SIGBUS, &handle_sigbus); - // SIGUSR1 is used for interrupting polling, forcing that thread - // to process new non-socket events. - SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing)); + // SIGUSR1 is used for interrupting polling, forcing the target + // thread to process new non-socket events. + // + // LibTorrent uses sockets for this purpose on Solaris and other + // platforms that do not properly pass signals to the target + // threads. Use '--enable-interrupt-socket' when configuring + // LibTorrent to enable this workaround. + if (torrent::thread_base::should_handle_sigusr1()) + SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing)); torrent::log_add_group_output(torrent::LOG_NOTICE, "important"); torrent::log_add_group_output(torrent::LOG_INFO, "complete"); diff --git a/src/thread_base.cc b/src/thread_base.cc index 19dab3b0..b4219cf9 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -160,7 +160,7 @@ ThreadBase::queue_item(thread_base_func newFunc) { // Make it also restart inactive threads? if (m_state == STATE_ACTIVE) - pthread_kill(m_thread, SIGUSR1); + interrupt(); } void @@ -168,7 +168,7 @@ ThreadBase::interrupt_main_polling() { int sleep_length = 0; while (ThreadBase::is_main_polling()) { - pthread_kill(torrent::main_thread()->pthread(), SIGUSR1); + torrent::main_thread()->interrupt(); if (!ThreadBase::is_main_polling()) return;