$OpenBSD: patch-src_thread_base_cc,v 1.1 2011/12/01 17:10:40 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	Thu Oct 20 12:32:53 2011
@@ -43,6 +43,7 @@
 #include <cstring>
 #include <iostream>
 #include <signal.h>
+#include <unistd.h>
 #include <rak/error_number.h>
 #include <torrent/exceptions.h>
 
@@ -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);
+  }
 }
