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/scheduler.rb | |
parent | 53547a9f2692ed3763ed213e4d11b98b124d4c66 (diff) | |
download | ranger-622ff1dc92abab26eabf5bea618797f515cbfaa4.tar.gz |
wip
Diffstat (limited to 'code/scheduler.rb')
-rw-r--r-- | code/scheduler.rb | 55 |
1 files changed, 55 insertions, 0 deletions
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 |