]> git.cworth.org Git - sup/commitdiff
Merge branch 'preemptive-loading' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 3 Sep 2009 17:53:47 +0000 (13:53 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 3 Sep 2009 17:53:47 +0000 (13:53 -0400)
bin/sup
lib/sup/modes/line-cursor-mode.rb
lib/sup/modes/thread-index-mode.rb

diff --git a/bin/sup b/bin/sup
index cdf1ff24169cc5b1da1e27d2cf4f03ac2969daa6..5049879cd16432661bb46fb8176b008f89c1eab2 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -58,6 +58,7 @@ if $opts[:list_hooks]
 end
 
 Thread.abort_on_exception = true # make debugging possible
+Thread.current.priority = 1 # keep ui responsive
 
 module Redwood
 
index 246f2b5461c69a7a53241d237fa7a647d14371fc..51a59134f1ca6a92effba651aec4404f5fb60b5a 100644 (file)
@@ -15,11 +15,24 @@ class LineCursorMode < ScrollMode
   def initialize opts={}
     @cursor_top = @curpos = opts.delete(:skip_top_rows) || 0
     @load_more_callbacks = []
-    @load_more_callbacks_m = Mutex.new
-    @load_more_callbacks_active = false
+    @load_more_q = Queue.new
+    @load_more_thread = ::Thread.new do
+      while true
+        e = @load_more_q.pop
+        debug "calling callbacks on #{e.inspect}"
+        @load_more_callbacks.each { |c| c.call e }
+      end
+    end
+
     super opts
   end
 
+  def cleanup
+    @load_more_thread.kill
+    debug "killing thread"
+    super
+  end
+
   def draw
     super
     set_status
@@ -77,7 +90,7 @@ protected
   end
 
   def cursor_down
-    call_load_more_callbacks buffer.content_height if @curpos == lines - 1
+    call_load_more_callbacks buffer.content_height if @curpos >= lines - [buffer.content_height/2,1].max
     return false unless @curpos < lines - 1
 
     if @curpos >= botline - 1
@@ -163,21 +176,8 @@ private
   end
 
   def call_load_more_callbacks size
-    go = 
-      @load_more_callbacks_m.synchronize do
-        if @load_more_callbacks_active
-          false
-        else
-          @load_more_callbacks_active = true
-        end
-    end
-
-    return unless go
-
-    @load_more_callbacks.each { |c| c.call size }
-    @load_more_callbacks_active = false
-  end    
-
+    @load_more_q.push size
+  end
 end
 
 end
index 5038d29f308fb5a609c783add43e401d011b34a9..82f258b689681183614b65d6475829ba10d0563e 100644 (file)
@@ -77,8 +77,7 @@ EOS
     @last_load_more_size = nil
     to_load_more do |size|
       next if @last_load_more_size == 0
-      load_threads :num => 1, :background => false
-      load_threads :num => (size - 1),
+      load_threads :num => size,
                    :when_done => lambda { |num| @last_load_more_size = num }
     end
   end
@@ -630,6 +629,7 @@ EOS
         BufferManager.draw_screen
         last_update = Time.now
       end
+      ::Thread.pass
       break if @interrupt_search
     end
     @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }