utilrb 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/utilrb/event_loop.rb +51 -49
- data/lib/utilrb/exception/full_message.rb +2 -1
- data/lib/utilrb/hash/slice.rb +2 -5
- data/lib/utilrb/kernel/arity.rb +11 -6
- data/lib/utilrb/kernel/load_dsl_file.rb +2 -2
- data/lib/utilrb/kernel/options.rb +3 -4
- data/lib/utilrb/logger/forward.rb +10 -0
- data/lib/utilrb/logger/hierarchy.rb +61 -19
- data/lib/utilrb/logger/root.rb +12 -12
- data/lib/utilrb/marshal/load_with_missing_constants.rb +18 -21
- data/lib/utilrb/marshal.rb +3 -0
- data/lib/utilrb/module/dsl_attribute.rb +37 -25
- data/lib/utilrb/object/address.rb +15 -3
- data/lib/utilrb/object/attribute.rb +2 -1
- data/lib/utilrb/pkgconfig.rb +346 -162
- data/lib/utilrb/test.rb +4 -4
- data/lib/utilrb/thread_pool.rb +29 -25
- data/lib/utilrb/timepoints.rb +7 -0
- data/lib/utilrb/version.rb +1 -1
- data/manifest.xml +1 -0
- data/utilrb.gemspec +1 -0
- metadata +21 -8
- data/.travis.yml +0 -9
data/lib/utilrb/test.rb
CHANGED
|
@@ -4,10 +4,10 @@ if ENV['TEST_ENABLE_COVERAGE'] != '0'
|
|
|
4
4
|
begin
|
|
5
5
|
require 'simplecov'
|
|
6
6
|
require 'coveralls'
|
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter
|
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
|
8
|
+
[SimpleCov::Formatter::HTMLFormatter,
|
|
9
|
+
Coveralls::SimpleCov::Formatter]
|
|
10
|
+
)
|
|
11
11
|
SimpleCov.start do
|
|
12
12
|
add_filter "/test/"
|
|
13
13
|
end
|
data/lib/utilrb/thread_pool.rb
CHANGED
|
@@ -9,8 +9,8 @@ module Utilrb
|
|
|
9
9
|
#
|
|
10
10
|
# @example Using a thread pool of 10 threads
|
|
11
11
|
# pool = ThreadPool.new(10)
|
|
12
|
-
# 0.upto(9) do
|
|
13
|
-
# pool.process do
|
|
12
|
+
# 0.upto(9) do
|
|
13
|
+
# pool.process do
|
|
14
14
|
# sleep 1
|
|
15
15
|
# puts "done"
|
|
16
16
|
# end
|
|
@@ -40,7 +40,7 @@ module Utilrb
|
|
|
40
40
|
attr_reader :pool
|
|
41
41
|
|
|
42
42
|
# State of the task
|
|
43
|
-
#
|
|
43
|
+
#
|
|
44
44
|
# @return [:waiting,:running,:stopping,:finished,:terminated,:exception] the state
|
|
45
45
|
attr_reader :state
|
|
46
46
|
|
|
@@ -54,7 +54,7 @@ module Utilrb
|
|
|
54
54
|
# return [Thread] the thread
|
|
55
55
|
attr_reader :thread
|
|
56
56
|
|
|
57
|
-
# The time the task was queued
|
|
57
|
+
# The time the task was queued
|
|
58
58
|
#
|
|
59
59
|
# return [Time] the time
|
|
60
60
|
attr_accessor :queued_at
|
|
@@ -115,15 +115,15 @@ module Utilrb
|
|
|
115
115
|
def exception?; @state == :exception; end
|
|
116
116
|
|
|
117
117
|
# A new task which can be added to the work queue of a {ThreadPool}.
|
|
118
|
-
# If a sync key is given no task having the same key will be
|
|
118
|
+
# If a sync key is given no task having the same key will be
|
|
119
119
|
# executed in parallel which is useful for instance member calls
|
|
120
120
|
# which are not thread safe.
|
|
121
121
|
#
|
|
122
122
|
# @param [Hash] options The options of the task.
|
|
123
123
|
# @option options [Object] :sync_key The sync key
|
|
124
124
|
# @option options [Proc] :callback The callback
|
|
125
|
-
# @option options [Object] :default Default value returned when an error ocurred which was handled.
|
|
126
|
-
# @param [Array] args The arguments for the code block
|
|
125
|
+
# @option options [Object] :default Default value returned when an error ocurred which was handled.
|
|
126
|
+
# @param [Array] args The arguments for the code block
|
|
127
127
|
# @param [#call] block The code block
|
|
128
128
|
def initialize (options = Hash.new,*args, &block)
|
|
129
129
|
unless block
|
|
@@ -162,7 +162,7 @@ module Utilrb
|
|
|
162
162
|
# returns true if the task has a default return vale
|
|
163
163
|
# @return [Boolean]
|
|
164
164
|
def default?
|
|
165
|
-
@mutex.synchronize do
|
|
165
|
+
@mutex.synchronize do
|
|
166
166
|
@default != nil
|
|
167
167
|
end
|
|
168
168
|
end
|
|
@@ -170,7 +170,7 @@ module Utilrb
|
|
|
170
170
|
#sets all internal state to running
|
|
171
171
|
#call execute after that.
|
|
172
172
|
def pre_execute(pool=nil)
|
|
173
|
-
@mutex.synchronize do
|
|
173
|
+
@mutex.synchronize do
|
|
174
174
|
#store current thread to be able to terminate
|
|
175
175
|
#the thread
|
|
176
176
|
@pool = pool
|
|
@@ -182,7 +182,7 @@ module Utilrb
|
|
|
182
182
|
|
|
183
183
|
# Executes the task.
|
|
184
184
|
# Should be called from a worker thread after pre_execute was called.
|
|
185
|
-
# After execute returned and the task was deleted
|
|
185
|
+
# After execute returned and the task was deleted
|
|
186
186
|
# from any internal list finalize must be called
|
|
187
187
|
# to propagate the task state.
|
|
188
188
|
def execute()
|
|
@@ -200,7 +200,7 @@ module Utilrb
|
|
|
200
200
|
end
|
|
201
201
|
@stopped_at = Time.now
|
|
202
202
|
end
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
# propagates the tasks state
|
|
205
205
|
# should be called after execute
|
|
206
206
|
def finalize
|
|
@@ -225,7 +225,7 @@ module Utilrb
|
|
|
225
225
|
end
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
-
# Called from the worker thread when the work is done
|
|
228
|
+
# Called from the worker thread when the work is done
|
|
229
229
|
#
|
|
230
230
|
# @yield [Object,Exception] The callback
|
|
231
231
|
def callback(&block)
|
|
@@ -249,6 +249,10 @@ module Utilrb
|
|
|
249
249
|
0
|
|
250
250
|
end
|
|
251
251
|
end
|
|
252
|
+
|
|
253
|
+
def to_s
|
|
254
|
+
"#<Utilrb::ThreadPool::Task #{@state} #{@block}>"
|
|
255
|
+
end
|
|
252
256
|
end
|
|
253
257
|
|
|
254
258
|
# The minimum number of worker threads.
|
|
@@ -270,12 +274,12 @@ module Utilrb
|
|
|
270
274
|
#
|
|
271
275
|
# @return [Fixnum]
|
|
272
276
|
attr_reader :waiting
|
|
273
|
-
|
|
277
|
+
|
|
274
278
|
# The average execution time of a (running) task.
|
|
275
279
|
#
|
|
276
280
|
# @return [Float]
|
|
277
281
|
attr_reader :avg_run_time
|
|
278
|
-
|
|
282
|
+
|
|
279
283
|
# The average waiting time of a task before being executed.
|
|
280
284
|
#
|
|
281
285
|
# @return [Float]
|
|
@@ -300,7 +304,7 @@ module Utilrb
|
|
|
300
304
|
|
|
301
305
|
@tasks_waiting = [] # tasks waiting for execution
|
|
302
306
|
@tasks_running = [] # tasks which are currently running
|
|
303
|
-
|
|
307
|
+
|
|
304
308
|
# Statistics
|
|
305
309
|
@avg_run_time = 0 # average run time of a task in s [Float]
|
|
306
310
|
@avg_wait_time = 0 # average time a task has to wait for execution in s [Float]
|
|
@@ -370,10 +374,10 @@ module Utilrb
|
|
|
370
374
|
end
|
|
371
375
|
|
|
372
376
|
# Number of tasks waiting for execution
|
|
373
|
-
#
|
|
377
|
+
#
|
|
374
378
|
# @return [Fixnum] the number of tasks
|
|
375
379
|
def backlog
|
|
376
|
-
@mutex.synchronize do
|
|
380
|
+
@mutex.synchronize do
|
|
377
381
|
@tasks_waiting.length
|
|
378
382
|
end
|
|
379
383
|
end
|
|
@@ -396,7 +400,7 @@ module Utilrb
|
|
|
396
400
|
process_with_options(nil,*args,&block)
|
|
397
401
|
end
|
|
398
402
|
|
|
399
|
-
# Returns true if a worker thread is currently processing a task
|
|
403
|
+
# Returns true if a worker thread is currently processing a task
|
|
400
404
|
# and no work is queued
|
|
401
405
|
#
|
|
402
406
|
# @return [Boolean]
|
|
@@ -426,7 +430,7 @@ module Utilrb
|
|
|
426
430
|
# safe.
|
|
427
431
|
#
|
|
428
432
|
# @param [Object] sync_key The sync key
|
|
429
|
-
# @yield [*args] the code block block
|
|
433
|
+
# @yield [*args] the code block block
|
|
430
434
|
# @return [Object] The result of the code block
|
|
431
435
|
def sync(sync_key,*args,&block)
|
|
432
436
|
raise ArgumentError,"no sync key" unless sync_key
|
|
@@ -454,7 +458,7 @@ module Utilrb
|
|
|
454
458
|
#
|
|
455
459
|
# @param [Object] sync_key The sync key
|
|
456
460
|
# @param [Float] timeout The timeout
|
|
457
|
-
# @yield [*args] the code block block
|
|
461
|
+
# @yield [*args] the code block block
|
|
458
462
|
# @return [Object] The result of the code block
|
|
459
463
|
def sync_timeout(sync_key,timeout,*args,&block)
|
|
460
464
|
raise ArgumentError,"no sync key" unless sync_key
|
|
@@ -480,14 +484,14 @@ module Utilrb
|
|
|
480
484
|
end
|
|
481
485
|
|
|
482
486
|
# Processes the given {Task} as soon as the next thread is available
|
|
483
|
-
#
|
|
487
|
+
#
|
|
484
488
|
# @param [Task] task The task.
|
|
485
489
|
# @return [Task]
|
|
486
490
|
def <<(task)
|
|
487
491
|
raise "cannot add task #{task} it is still running" if task.thread
|
|
488
492
|
task.reset if task.finished?
|
|
489
493
|
@mutex.synchronize do
|
|
490
|
-
if shutdown?
|
|
494
|
+
if shutdown?
|
|
491
495
|
raise "unable to add work while shutting down"
|
|
492
496
|
end
|
|
493
497
|
task.queued_at = Time.now
|
|
@@ -500,7 +504,7 @@ module Utilrb
|
|
|
500
504
|
task
|
|
501
505
|
end
|
|
502
506
|
|
|
503
|
-
# Trims the number of threads if threads are waiting for work and
|
|
507
|
+
# Trims the number of threads if threads are waiting for work and
|
|
504
508
|
# the number of spawned threads is higher than the minimum number.
|
|
505
509
|
#
|
|
506
510
|
# @param [boolean] force Trim even if no thread is waiting.
|
|
@@ -551,12 +555,12 @@ module Utilrb
|
|
|
551
555
|
|
|
552
556
|
private
|
|
553
557
|
|
|
554
|
-
#calculates the moving average
|
|
558
|
+
#calculates the moving average
|
|
555
559
|
def moving_average(current_val,new_val)
|
|
556
560
|
return new_val if current_val == 0
|
|
557
561
|
current_val * 0.95 + new_val * 0.05
|
|
558
562
|
end
|
|
559
|
-
|
|
563
|
+
|
|
560
564
|
# spawns a worker thread
|
|
561
565
|
# must be called from a synchronized block
|
|
562
566
|
def spawn_thread
|
data/lib/utilrb/timepoints.rb
CHANGED
|
@@ -15,8 +15,15 @@ module Utilrb
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def format_timepoints
|
|
18
|
+
start_points = Hash.new
|
|
18
19
|
result = []
|
|
19
20
|
@timepoints.inject(@timepoints.first.first) do |last_t, (t, name)|
|
|
21
|
+
if name.last == 'start'
|
|
22
|
+
start_points[name[0..-2]] = t
|
|
23
|
+
elsif name.last == 'done'
|
|
24
|
+
total = t - start_points.delete(name[0..-2])
|
|
25
|
+
name = name + ["total=%.3f" % total]
|
|
26
|
+
end
|
|
20
27
|
result << name + [t - last_t]
|
|
21
28
|
t
|
|
22
29
|
end
|
data/lib/utilrb/version.rb
CHANGED
data/manifest.xml
CHANGED
data/utilrb.gemspec
CHANGED
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
|
19
19
|
|
|
20
20
|
s.add_runtime_dependency "facets", ">= 2.4.0"
|
|
21
21
|
s.add_runtime_dependency "rake", ">= 0.9"
|
|
22
|
+
s.add_runtime_dependency "backports", "~> 3.11"
|
|
22
23
|
s.add_development_dependency "flexmock", ">= 2.0.0"
|
|
23
24
|
s.add_development_dependency "minitest", ">= 5.0", "~> 5.0"
|
|
24
25
|
s.add_development_dependency "coveralls"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: utilrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sylvain Joyeux
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-06-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: facets
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0.9'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: backports
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.11'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.11'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: flexmock
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -98,7 +112,6 @@ files:
|
|
|
98
112
|
- ".boring"
|
|
99
113
|
- ".gemtest"
|
|
100
114
|
- ".gitignore"
|
|
101
|
-
- ".travis.yml"
|
|
102
115
|
- CMakeLists.txt
|
|
103
116
|
- Gemfile
|
|
104
117
|
- History.txt
|
|
@@ -152,6 +165,7 @@ files:
|
|
|
152
165
|
- lib/utilrb/logger/log_pp.rb
|
|
153
166
|
- lib/utilrb/logger/root.rb
|
|
154
167
|
- lib/utilrb/logger/silent.rb
|
|
168
|
+
- lib/utilrb/marshal.rb
|
|
155
169
|
- lib/utilrb/marshal/load_with_missing_constants.rb
|
|
156
170
|
- lib/utilrb/module.rb
|
|
157
171
|
- lib/utilrb/module/ancestor_p.rb
|
|
@@ -200,7 +214,7 @@ homepage: http://rock-robotics.org
|
|
|
200
214
|
licenses:
|
|
201
215
|
- BSD
|
|
202
216
|
metadata: {}
|
|
203
|
-
post_install_message:
|
|
217
|
+
post_install_message:
|
|
204
218
|
rdoc_options: []
|
|
205
219
|
require_paths:
|
|
206
220
|
- lib
|
|
@@ -215,9 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
215
229
|
- !ruby/object:Gem::Version
|
|
216
230
|
version: '0'
|
|
217
231
|
requirements: []
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
signing_key:
|
|
232
|
+
rubygems_version: 3.4.20
|
|
233
|
+
signing_key:
|
|
221
234
|
specification_version: 4
|
|
222
235
|
summary: Utilrb is yet another Ruby toolkit, in the spirit of facets
|
|
223
236
|
test_files: []
|