about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--code/directory.rb3
-rw-r--r--code/draw.rb2
-rw-r--r--code/fm.rb43
-rw-r--r--code/scheduler.rb55
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
lt'>
f2d8598d ^
f6910552 ^
f2d8598d ^
f6910552 ^


d955e3f0 ^
f2d8598d ^
f6910552 ^
f2d8598d ^
291ca616 ^

f6910552 ^

f2d8598d ^



b4b0eb24 ^

f2d8598d ^










291ca616 ^
f2d8598d ^

ea87d005 ^
08f21ae5 ^

f2d8598d ^


291ca616 ^

f2d8598d ^


8eecaa8a ^
f2d8598d ^


b4b0eb24 ^


291ca616 ^

f2d8598d ^






f6910552 ^

f2d8598d ^
b4b0eb24 ^

ea87d005 ^
f6910552 ^
f2d8598d ^
d955e3f0 ^
f6910552 ^



0a1bc759 ^
f6910552 ^



ea87d005 ^
f6910552 ^



ea87d005 ^
f6910552 ^




0a1bc759 ^
f6910552 ^
0a1bc759 ^
f6910552 ^

0a1bc759 ^
f6910552 ^
0a1bc759 ^
f6910552 ^
d955e3f0 ^
6874e0ea ^

f2d8598d ^
b4b0eb24 ^
f6910552 ^
0128bee7 ^

6874e0ea ^
ca4b999c ^
6874e0ea ^

6874e0ea ^
ce421875 ^



6874e0ea ^

ca4b999c ^
f2d8598d ^


f2d8598d ^
0128bee7 ^



501f5014 ^
75013dc7 ^



501f5014 ^

f2d8598d ^










ea87d005 ^
d955e3f0 ^



f2d8598d ^

d955e3f0 ^
f2d8598d ^


0128bee7 ^

f2d8598d ^



ea87d005 ^
f2d8598d ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211