diff options
author | hut <hut@lavabit.com> | 2009-06-11 16:12:18 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-06-11 16:12:18 +0200 |
commit | 622ff1dc92abab26eabf5bea618797f515cbfaa4 (patch) | |
tree | b7e6f7d54d6f9f7fb872fc98a4679f507ff5cbc4 /code | |
parent | 53547a9f2692ed3763ed213e4d11b98b124d4c66 (diff) | |
download | ranger-622ff1dc92abab26eabf5bea618797f515cbfaa4.tar.gz |
wip
Diffstat (limited to 'code')
-rw-r--r-- | code/directory.rb | 3 | ||||
-rw-r--r-- | code/draw.rb | 2 | ||||
-rw-r--r-- | code/fm.rb | 43 | ||||
-rw-r--r-- | code/scheduler.rb | 55 |
4 files changed, 61 insertions, 42 deletions
diff --git a/code/directory.rb b/code/directory.rb index a5bee819..0b1e4e60 100644 --- a/code/directory.rb +++ b/code/directory.rb @@ -298,8 +298,7 @@ class Directory end def schedule() - @scheduled = true - Fm.schedule(self) + Scheduler << self end def refresh!() diff --git a/code/draw.rb b/code/draw.rb index 67615afd..175a9a1a 100644 --- a/code/draw.rb +++ b/code/draw.rb @@ -137,7 +137,7 @@ module Fm elsif not d.read? puti l, left, 'reading...'.ljust(wid+1) - d.schedule unless d.scheduled? + Scheduler << d else puti l, left, 'ERROR'.ljust(wid+1) diff --git a/code/fm.rb b/code/fm.rb index 3b5ff852..77dd327c 100644 --- a/code/fm.rb +++ b/code/fm.rb @@ -20,12 +20,9 @@ class Void end module Fm - SCHEDULER_PRIORITY = -1 COPY_PRIORITY = -2 - SCHEDULED = [] COLUMNS = 4 - UPDATE_SIGNAL = 31 VI = "vi -c 'map h :quit<CR>' -c 'map q :quit<CR>'" << " -c 'map H :unmap h<CR>:unmap H<CR>' %s" @@ -62,7 +59,7 @@ module Fm # Give me some way to redraw screen while waiting for # input from Interface.geti - Signal.trap(UPDATE_SIGNAL) do + Signal.trap(Scheduler::UPDATE_SIGNAL) do @pwd.refresh draw end @@ -82,27 +79,7 @@ module Fm def self.boot_up(pwd=nil) pwd ||= @pwd.path || Dir.getwd - # This thread inspects directories - @scheduler_active = false - if defined? @mcheduler and Thread === @mcheduler - @mcheduler.kill - end - @mcheduler = Thread.new do - while true -# Thread.stop - sleep 0.1 - if @scheduler_active and !SCHEDULED.empty? - while dir = SCHEDULED.shift - dir.refresh(true) - dir.resize - force_update - end - end - end - end - @scheduler = Void - @scheduler.priority = SCHEDULER_PRIORITY - + Scheduler.reset @dirs = Hash.new() do |hash, key| hash[key] = newdir = Directory.new(key) @@ -113,13 +90,7 @@ module Fm @path = [@dirs['/']] enter_dir(pwd) - @scheduler_active = true - @scheduler.run - end - - def self.force_update - # Send a signal to this process - Process.kill(UPDATE_SIGNAL, PID) + Scheduler.run end def self.lines @@ -232,7 +203,7 @@ module Fm i = 0 @path.each_with_index do |p, i| - schedule(p) + p.schedule unless i == @path.size - 1 p.pointed_file = @path[i+1].path end @@ -250,12 +221,6 @@ module Fm end end - def self.schedule(dir) - dir.scheduled = true - SCHEDULED << dir - @scheduler.run - end - def self.move_to_trash!(fn) unless File.exists?(@trash) Dir.mkdir(@trash) diff --git a/code/scheduler.rb b/code/scheduler.rb new file mode 100644 index 00000000..8624c18a --- /dev/null +++ b/code/scheduler.rb @@ -0,0 +1,55 @@ +require 'thread' + +# This thread inspects directories +module Scheduler + extend self + + UPDATE_SIGNAL = 31 + PRIORITY = -1 + + def reset() + @scheduled = [] + @active = false + + @thread ||= Thread.new do + Thread.current.priority = PRIORITY + while true + sleep 0.1 + if @active and not @scheduled.empty? + while dir = @scheduled.shift + dir.refresh(true) + dir.resize + force_update + end + end + end + end + end + + def run + @active = true + end + + def stop + @active = false + end + + def <<(dir) + dir.scheduled = true + unless include? dir + @scheduled << dir + end + end + + def include?(dir) + @scheduled.include?(dir) + end + + def force_update + Process.kill( UPDATE_SIGNAL, PID ) + end + +# def priority() @thread.priority end +# def priority=(x) @thread.priority=(x) end + +end |