openbsd-ports/net/rtorrent/patches/patch-src_thread_base_cc
2012-07-15 10:20:07 +00:00

45 lines
1.4 KiB
Plaintext

$OpenBSD: patch-src_thread_base_cc,v 1.3 2012/07/15 10:20:07 dcoppa Exp $
Fix an issue causing high loads while waiting for main thread to
exit polling (upstream git commit ce166217075e2368e8ad19ef91737fad2e3f918f)
--- src/thread_base.cc.orig Tue Apr 5 12:26:11 2011
+++ src/thread_base.cc Fri Jul 13 12:21:05 2012
@@ -43,6 +43,7 @@
#include <cstring>
#include <iostream>
#include <signal.h>
+#include <unistd.h>
#include <rak/error_number.h>
#include <torrent/exceptions.h>
@@ -61,7 +62,7 @@ class lt_cacheline_aligned thread_queue_hack { (public
static const unsigned int max_size = 32;
- thread_queue_hack() { std::memset(this, 0, sizeof(thread_queue_hack)); }
+ thread_queue_hack() : m_lock(0) { std::memset(this, 0, sizeof(thread_queue_hack)); }
void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) usleep(0); }
void unlock() { __sync_bool_compare_and_swap(&m_lock, 1, 0); }
@@ -201,10 +202,15 @@ ThreadBase::queue_item(thread_base_func newFunc) {
void
ThreadBase::interrupt_main_polling() {
- do {
+ int sleep_length = 0;
+
+ while (ThreadBase::is_main_polling()) {
+ pthread_kill(main_thread->m_thread, SIGUSR1);
+
if (!ThreadBase::is_main_polling())
return;
-
- pthread_kill(main_thread->m_thread, SIGUSR1);
- } while (1);
+
+ usleep(sleep_length);
+ sleep_length = std::min(sleep_length + 50, 1000);
+ }
}