concurrent-ruby 1.1.5 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +84 -1
- data/Gemfile +5 -10
- data/{LICENSE.md → LICENSE.txt} +18 -20
- data/README.md +55 -31
- data/Rakefile +84 -92
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java +0 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaSemaphoreLibrary.java +52 -22
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/SynchronizationLibrary.java +10 -25
- data/lib/{concurrent → concurrent-ruby/concurrent}/agent.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/array.rb +6 -16
- data/lib/{concurrent → concurrent-ruby/concurrent}/async.rb +10 -20
- data/lib/{concurrent → concurrent-ruby/concurrent}/atom.rb +2 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/atomic_boolean.rb +7 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/atomic_fixnum.rb +5 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/atomic_markable_reference.rb +3 -0
- data/lib/concurrent-ruby/concurrent/atomic/atomic_reference.rb +135 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/cyclic_barrier.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/event.rb +3 -3
- data/lib/concurrent-ruby/concurrent/atomic/fiber_local_var.rb +109 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/java_count_down_latch.rb +1 -0
- data/lib/concurrent-ruby/concurrent/atomic/locals.rb +189 -0
- data/lib/concurrent-ruby/concurrent/atomic/lock_local_var.rb +28 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_atomic_boolean.rb +11 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_atomic_fixnum.rb +11 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_count_down_latch.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_semaphore.rb +19 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/read_write_lock.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/reentrant_read_write_lock.rb +9 -9
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/semaphore.rb +32 -14
- data/lib/concurrent-ruby/concurrent/atomic/thread_local_var.rb +111 -0
- data/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb +37 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic_reference/mutex_atomic.rb +15 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/copy_on_notify_observer_set.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/copy_on_write_observer_set.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/lock_free_stack.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/mri_map_backend.rb +3 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/non_concurrent_map_backend.rb +16 -8
- data/lib/concurrent-ruby/concurrent/collection/map/truffleruby_map_backend.rb +14 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/ruby_non_concurrent_priority_queue.rb +11 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/dereferenceable.rb +2 -2
- data/lib/concurrent-ruby/concurrent/concern/logging.rb +116 -0
- data/lib/concurrent-ruby/concurrent/concurrent_ruby.jar +0 -0
- data/lib/concurrent-ruby/concurrent/configuration.rb +105 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/delay.rb +2 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/errors.rb +5 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/exchanger.rb +1 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/abstract_executor_service.rb +34 -37
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/cached_thread_pool.rb +4 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/executor_service.rb +2 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/fixed_thread_pool.rb +29 -15
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_executor_service.rb +21 -9
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_single_thread_executor.rb +4 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_thread_pool_executor.rb +19 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_executor_service.rb +10 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_single_thread_executor.rb +0 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_thread_pool_executor.rb +46 -42
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/safe_task_executor.rb +6 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serialized_execution.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/simple_executor_service.rb +5 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/single_thread_executor.rb +1 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/thread_pool_executor.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/timer_set.rb +0 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/hash.rb +1 -10
- data/lib/{concurrent → concurrent-ruby/concurrent}/immutable_struct.rb +10 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/ivar.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/map.rb +44 -31
- data/lib/{concurrent → concurrent-ruby/concurrent}/maybe.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/mutable_struct.rb +13 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/mvar.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/promise.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/promises.rb +7 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/re_include.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/scheduled_task.rb +30 -17
- data/lib/{concurrent → concurrent-ruby/concurrent}/set.rb +17 -19
- data/lib/{concurrent → concurrent-ruby/concurrent}/settable_struct.rb +13 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_lockable_object.rb +5 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_object.rb +1 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_struct.rb +11 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/condition.rb +2 -0
- data/lib/concurrent-ruby/concurrent/synchronization/full_memory_barrier.rb +29 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/jruby_lockable_object.rb +3 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/lock.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/lockable_object.rb +8 -7
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/mutex_lockable_object.rb +18 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/object.rb +12 -44
- data/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb +36 -0
- data/lib/concurrent-ruby/concurrent/synchronization/volatile.rb +101 -0
- data/lib/concurrent-ruby/concurrent/synchronization.rb +13 -0
- data/lib/concurrent-ruby/concurrent/thread_safe/synchronized_delegator.rb +47 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/cheap_lockable.rb +2 -39
- data/lib/concurrent-ruby/concurrent/thread_safe/util/data_structures.rb +52 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/striped64.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/timer_task.rb +11 -34
- data/lib/{concurrent → concurrent-ruby/concurrent}/tuple.rb +1 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/tvar.rb +21 -57
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/engine.rb +5 -16
- data/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb +19 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/native_extension_loader.rb +8 -10
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/native_integer.rb +1 -0
- data/lib/concurrent-ruby/concurrent/utility/processor_counter.rb +110 -0
- data/lib/concurrent-ruby/concurrent/version.rb +3 -0
- data/lib/concurrent-ruby/concurrent-ruby.rb +5 -0
- metadata +127 -129
- data/lib/concurrent/atomic/abstract_thread_local_var.rb +0 -66
- data/lib/concurrent/atomic/atomic_reference.rb +0 -204
- data/lib/concurrent/atomic/java_thread_local_var.rb +0 -37
- data/lib/concurrent/atomic/ruby_thread_local_var.rb +0 -161
- data/lib/concurrent/atomic/thread_local_var.rb +0 -104
- data/lib/concurrent/concern/logging.rb +0 -32
- data/lib/concurrent/concurrent_ruby.jar +0 -0
- data/lib/concurrent/configuration.rb +0 -184
- data/lib/concurrent/synchronization/jruby_object.rb +0 -45
- data/lib/concurrent/synchronization/mri_object.rb +0 -44
- data/lib/concurrent/synchronization/rbx_lockable_object.rb +0 -65
- data/lib/concurrent/synchronization/rbx_object.rb +0 -49
- data/lib/concurrent/synchronization/truffleruby_object.rb +0 -47
- data/lib/concurrent/synchronization/volatile.rb +0 -36
- data/lib/concurrent/synchronization.rb +0 -30
- data/lib/concurrent/thread_safe/synchronized_delegator.rb +0 -50
- data/lib/concurrent/thread_safe/util/data_structures.rb +0 -63
- data/lib/concurrent/utility/at_exit.rb +0 -97
- data/lib/concurrent/utility/monotonic_time.rb +0 -58
- data/lib/concurrent/utility/processor_counter.rb +0 -158
- data/lib/concurrent/version.rb +0 -3
- data/lib/concurrent-ruby.rb +0 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/count_down_latch.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic_reference/numeric_cas_wrapper.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomics.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/java_non_concurrent_priority_queue.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/atomic_reference_map_backend.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/synchronized_map_backend.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/non_concurrent_priority_queue.rb +1 -1
- /data/lib/{concurrent → concurrent-ruby/concurrent}/concern/deprecation.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/concern/obligation.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/concern/observable.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/constants.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/dataflow.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/executor/immediate_executor.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/executor/indirect_immediate_executor.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serial_executor_service.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serialized_execution_delegator.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/executors.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/future.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/options.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/adder.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/power_of_two_tuple.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/volatile.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/xor_shift_random.rb +0 -0
- /data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util.rb +0 -0
- /data/lib/{concurrent.rb → concurrent-ruby/concurrent.rb} +0 -0
@@ -1,47 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
module Synchronization
|
3
|
-
|
4
|
-
# @!visibility private
|
5
|
-
module TruffleRubyAttrVolatile
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(ClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def attr_volatile(*names)
|
12
|
-
names.each do |name|
|
13
|
-
ivar = :"@volatile_#{name}"
|
14
|
-
|
15
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
16
|
-
def #{name}
|
17
|
-
full_memory_barrier
|
18
|
-
#{ivar}
|
19
|
-
end
|
20
|
-
|
21
|
-
def #{name}=(value)
|
22
|
-
#{ivar} = value
|
23
|
-
full_memory_barrier
|
24
|
-
end
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
names.map { |n| [n, :"#{n}="] }.flatten
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def full_memory_barrier
|
33
|
-
TruffleRuby.full_memory_barrier
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# @!visibility private
|
38
|
-
# @!macro internal_implementation_note
|
39
|
-
class TruffleRubyObject < AbstractObject
|
40
|
-
include TruffleRubyAttrVolatile
|
41
|
-
|
42
|
-
def initialize
|
43
|
-
# nothing to do
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
module Synchronization
|
3
|
-
|
4
|
-
# Volatile adds the attr_volatile class method when included.
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# class Foo
|
8
|
-
# include Concurrent::Synchronization::Volatile
|
9
|
-
#
|
10
|
-
# attr_volatile :bar
|
11
|
-
#
|
12
|
-
# def initialize
|
13
|
-
# self.bar = 1
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# foo = Foo.new
|
18
|
-
# foo.bar
|
19
|
-
# => 1
|
20
|
-
# foo.bar = 2
|
21
|
-
# => 2
|
22
|
-
|
23
|
-
Volatile = case
|
24
|
-
when Concurrent.on_cruby?
|
25
|
-
MriAttrVolatile
|
26
|
-
when Concurrent.on_jruby?
|
27
|
-
JRubyAttrVolatile
|
28
|
-
when Concurrent.on_rbx?
|
29
|
-
RbxAttrVolatile
|
30
|
-
when Concurrent.on_truffleruby?
|
31
|
-
TruffleRubyAttrVolatile
|
32
|
-
else
|
33
|
-
MriAttrVolatile
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'concurrent/utility/engine'
|
2
|
-
|
3
|
-
require 'concurrent/synchronization/abstract_object'
|
4
|
-
require 'concurrent/utility/native_extension_loader' # load native parts first
|
5
|
-
Concurrent.load_native_extensions
|
6
|
-
|
7
|
-
require 'concurrent/synchronization/mri_object'
|
8
|
-
require 'concurrent/synchronization/jruby_object'
|
9
|
-
require 'concurrent/synchronization/rbx_object'
|
10
|
-
require 'concurrent/synchronization/truffleruby_object'
|
11
|
-
require 'concurrent/synchronization/object'
|
12
|
-
require 'concurrent/synchronization/volatile'
|
13
|
-
|
14
|
-
require 'concurrent/synchronization/abstract_lockable_object'
|
15
|
-
require 'concurrent/synchronization/mutex_lockable_object'
|
16
|
-
require 'concurrent/synchronization/jruby_lockable_object'
|
17
|
-
require 'concurrent/synchronization/rbx_lockable_object'
|
18
|
-
|
19
|
-
require 'concurrent/synchronization/lockable_object'
|
20
|
-
|
21
|
-
require 'concurrent/synchronization/condition'
|
22
|
-
require 'concurrent/synchronization/lock'
|
23
|
-
|
24
|
-
module Concurrent
|
25
|
-
# {include:file:docs-source/synchronization.md}
|
26
|
-
# {include:file:docs-source/synchronization-notes.md}
|
27
|
-
module Synchronization
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'delegate'
|
2
|
-
require 'monitor'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
unless defined?(SynchronizedDelegator)
|
6
|
-
|
7
|
-
# This class provides a trivial way to synchronize all calls to a given object
|
8
|
-
# by wrapping it with a `Delegator` that performs `Monitor#enter/exit` calls
|
9
|
-
# around the delegated `#send`. Example:
|
10
|
-
#
|
11
|
-
# array = [] # not thread-safe on many impls
|
12
|
-
# array = SynchronizedDelegator.new([]) # thread-safe
|
13
|
-
#
|
14
|
-
# A simple `Monitor` provides a very coarse-grained way to synchronize a given
|
15
|
-
# object, in that it will cause synchronization for methods that have no need
|
16
|
-
# for it, but this is a trivial way to get thread-safety where none may exist
|
17
|
-
# currently on some implementations.
|
18
|
-
#
|
19
|
-
# This class is currently being considered for inclusion into stdlib, via
|
20
|
-
# https://bugs.ruby-lang.org/issues/8556
|
21
|
-
#
|
22
|
-
# @!visibility private
|
23
|
-
class SynchronizedDelegator < SimpleDelegator
|
24
|
-
def setup
|
25
|
-
@old_abort = Thread.abort_on_exception
|
26
|
-
Thread.abort_on_exception = true
|
27
|
-
end
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
Thread.abort_on_exception = @old_abort
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize(obj)
|
34
|
-
__setobj__(obj)
|
35
|
-
@monitor = Monitor.new
|
36
|
-
end
|
37
|
-
|
38
|
-
def method_missing(method, *args, &block)
|
39
|
-
monitor = @monitor
|
40
|
-
begin
|
41
|
-
monitor.enter
|
42
|
-
super
|
43
|
-
ensure
|
44
|
-
monitor.exit
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'concurrent/thread_safe/util'
|
2
|
-
|
3
|
-
# Shim for TruffleRuby.synchronized
|
4
|
-
if Concurrent.on_truffleruby? && !TruffleRuby.respond_to?(:synchronized)
|
5
|
-
module TruffleRuby
|
6
|
-
def self.synchronized(object, &block)
|
7
|
-
Truffle::System.synchronized(object, &block)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module Concurrent
|
13
|
-
module ThreadSafe
|
14
|
-
module Util
|
15
|
-
def self.make_synchronized_on_rbx(klass)
|
16
|
-
klass.class_eval do
|
17
|
-
private
|
18
|
-
|
19
|
-
def _mon_initialize
|
20
|
-
@_monitor = Monitor.new unless @_monitor # avoid double initialisation
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.new(*args)
|
24
|
-
obj = super(*args)
|
25
|
-
obj.send(:_mon_initialize)
|
26
|
-
obj
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
klass.superclass.instance_methods(false).each do |method|
|
31
|
-
case method
|
32
|
-
when :new_range, :new_reserved
|
33
|
-
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
34
|
-
def #{method}(*args)
|
35
|
-
obj = super
|
36
|
-
obj.send(:_mon_initialize)
|
37
|
-
obj
|
38
|
-
end
|
39
|
-
RUBY
|
40
|
-
else
|
41
|
-
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
42
|
-
def #{method}(*args)
|
43
|
-
monitor = @_monitor
|
44
|
-
monitor or raise("BUG: Internal monitor was not properly initialized. Please report this to the concurrent-ruby developers.")
|
45
|
-
monitor.synchronize { super }
|
46
|
-
end
|
47
|
-
RUBY
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.make_synchronized_on_truffleruby(klass)
|
53
|
-
klass.superclass.instance_methods(false).each do |method|
|
54
|
-
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
55
|
-
def #{method}(*args, &block)
|
56
|
-
TruffleRuby.synchronized(self) { super(*args, &block) }
|
57
|
-
end
|
58
|
-
RUBY
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'concurrent/synchronization'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
|
6
|
-
# Provides ability to add and remove handlers to be run at `Kernel#at_exit`, order is undefined.
|
7
|
-
# Each handler is executed at most once.
|
8
|
-
#
|
9
|
-
# @!visibility private
|
10
|
-
class AtExitImplementation < Synchronization::LockableObject
|
11
|
-
include Logger::Severity
|
12
|
-
|
13
|
-
def initialize(*args)
|
14
|
-
super()
|
15
|
-
synchronize { ns_initialize(*args) }
|
16
|
-
end
|
17
|
-
|
18
|
-
# Add a handler to be run at `Kernel#at_exit`
|
19
|
-
# @param [Object] handler_id optionally provide an id, if already present, handler is replaced
|
20
|
-
# @yield the handler
|
21
|
-
# @return id of the handler
|
22
|
-
def add(handler_id = nil, &handler)
|
23
|
-
id = handler_id || handler.object_id
|
24
|
-
synchronize { @handlers[id] = handler }
|
25
|
-
id
|
26
|
-
end
|
27
|
-
|
28
|
-
# Delete a handler by handler_id
|
29
|
-
# @return [true, false]
|
30
|
-
def delete(handler_id)
|
31
|
-
!!synchronize { @handlers.delete handler_id }
|
32
|
-
end
|
33
|
-
|
34
|
-
# Is handler with handler_id rpesent?
|
35
|
-
# @return [true, false]
|
36
|
-
def handler?(handler_id)
|
37
|
-
synchronize { @handlers.key? handler_id }
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return copy of the handlers
|
41
|
-
def handlers
|
42
|
-
synchronize { @handlers }.clone
|
43
|
-
end
|
44
|
-
|
45
|
-
# install `Kernel#at_exit` callback to execute added handlers
|
46
|
-
def install
|
47
|
-
synchronize do
|
48
|
-
@installed ||= begin
|
49
|
-
at_exit { runner }
|
50
|
-
true
|
51
|
-
end
|
52
|
-
self
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Will it run during `Kernel#at_exit`
|
57
|
-
def enabled?
|
58
|
-
synchronize { @enabled }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Configure if it runs during `Kernel#at_exit`
|
62
|
-
def enabled=(value)
|
63
|
-
synchronize { @enabled = value }
|
64
|
-
end
|
65
|
-
|
66
|
-
# run the handlers manually
|
67
|
-
# @return ids of the handlers
|
68
|
-
def run
|
69
|
-
handlers, _ = synchronize { handlers, @handlers = @handlers, {} }
|
70
|
-
handlers.each do |_, handler|
|
71
|
-
begin
|
72
|
-
handler.call
|
73
|
-
rescue => error
|
74
|
-
Concurrent.global_logger.call(ERROR, error)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
handlers.keys
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def ns_initialize(enabled = true)
|
83
|
-
@handlers = {}
|
84
|
-
@enabled = enabled
|
85
|
-
end
|
86
|
-
|
87
|
-
def runner
|
88
|
-
run if synchronize { @enabled }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
private_constant :AtExitImplementation
|
93
|
-
|
94
|
-
# @see AtExitImplementation
|
95
|
-
# @!visibility private
|
96
|
-
AtExit = AtExitImplementation.new.install
|
97
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'concurrent/synchronization'
|
2
|
-
|
3
|
-
module Concurrent
|
4
|
-
|
5
|
-
class_definition = Class.new(Synchronization::LockableObject) do
|
6
|
-
def initialize
|
7
|
-
@last_time = Time.now.to_f
|
8
|
-
super()
|
9
|
-
end
|
10
|
-
|
11
|
-
if defined?(Process::CLOCK_MONOTONIC)
|
12
|
-
# @!visibility private
|
13
|
-
def get_time
|
14
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
15
|
-
end
|
16
|
-
elsif Concurrent.on_jruby?
|
17
|
-
# @!visibility private
|
18
|
-
def get_time
|
19
|
-
java.lang.System.nanoTime() / 1_000_000_000.0
|
20
|
-
end
|
21
|
-
else
|
22
|
-
|
23
|
-
# @!visibility private
|
24
|
-
def get_time
|
25
|
-
synchronize do
|
26
|
-
now = Time.now.to_f
|
27
|
-
if @last_time < now
|
28
|
-
@last_time = now
|
29
|
-
else # clock has moved back in time
|
30
|
-
@last_time += 0.000_001
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Clock that cannot be set and represents monotonic time since
|
39
|
-
# some unspecified starting point.
|
40
|
-
#
|
41
|
-
# @!visibility private
|
42
|
-
GLOBAL_MONOTONIC_CLOCK = class_definition.new
|
43
|
-
private_constant :GLOBAL_MONOTONIC_CLOCK
|
44
|
-
|
45
|
-
# @!macro monotonic_get_time
|
46
|
-
#
|
47
|
-
# Returns the current time a tracked by the application monotonic clock.
|
48
|
-
#
|
49
|
-
# @return [Float] The current monotonic time since some unspecified
|
50
|
-
# starting point
|
51
|
-
#
|
52
|
-
# @!macro monotonic_clock_warning
|
53
|
-
def monotonic_time
|
54
|
-
GLOBAL_MONOTONIC_CLOCK.get_time
|
55
|
-
end
|
56
|
-
|
57
|
-
module_function :monotonic_time
|
58
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'concurrent/delay'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
module Utility
|
6
|
-
|
7
|
-
# @!visibility private
|
8
|
-
class ProcessorCounter
|
9
|
-
def initialize
|
10
|
-
@processor_count = Delay.new { compute_processor_count }
|
11
|
-
@physical_processor_count = Delay.new { compute_physical_processor_count }
|
12
|
-
end
|
13
|
-
|
14
|
-
# Number of processors seen by the OS and used for process scheduling. For
|
15
|
-
# performance reasons the calculated value will be memoized on the first
|
16
|
-
# call.
|
17
|
-
#
|
18
|
-
# When running under JRuby the Java runtime call
|
19
|
-
# `java.lang.Runtime.getRuntime.availableProcessors` will be used. According
|
20
|
-
# to the Java documentation this "value may change during a particular
|
21
|
-
# invocation of the virtual machine... [applications] should therefore
|
22
|
-
# occasionally poll this property." Subsequently the result will NOT be
|
23
|
-
# memoized under JRuby.
|
24
|
-
#
|
25
|
-
# On Windows the Win32 API will be queried for the
|
26
|
-
# `NumberOfLogicalProcessors from Win32_Processor`. This will return the
|
27
|
-
# total number "logical processors for the current instance of the
|
28
|
-
# processor", which taked into account hyperthreading.
|
29
|
-
#
|
30
|
-
# * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
|
31
|
-
# * Alpha: /usr/bin/nproc (/proc/cpuinfo exists but cannot be used)
|
32
|
-
# * BSD: /sbin/sysctl
|
33
|
-
# * Cygwin: /proc/cpuinfo
|
34
|
-
# * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
|
35
|
-
# * HP-UX: /usr/sbin/ioscan
|
36
|
-
# * IRIX: /usr/sbin/sysconf
|
37
|
-
# * Linux: /proc/cpuinfo
|
38
|
-
# * Minix 3+: /proc/cpuinfo
|
39
|
-
# * Solaris: /usr/sbin/psrinfo
|
40
|
-
# * Tru64 UNIX: /usr/sbin/psrinfo
|
41
|
-
# * UnixWare: /usr/sbin/psrinfo
|
42
|
-
#
|
43
|
-
# @return [Integer] number of processors seen by the OS or Java runtime
|
44
|
-
#
|
45
|
-
# @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
|
46
|
-
#
|
47
|
-
# @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
|
48
|
-
# @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
|
49
|
-
def processor_count
|
50
|
-
@processor_count.value
|
51
|
-
end
|
52
|
-
|
53
|
-
# Number of physical processor cores on the current system. For performance
|
54
|
-
# reasons the calculated value will be memoized on the first call.
|
55
|
-
#
|
56
|
-
# On Windows the Win32 API will be queried for the `NumberOfCores from
|
57
|
-
# Win32_Processor`. This will return the total number "of cores for the
|
58
|
-
# current instance of the processor." On Unix-like operating systems either
|
59
|
-
# the `hwprefs` or `sysctl` utility will be called in a subshell and the
|
60
|
-
# returned value will be used. In the rare case where none of these methods
|
61
|
-
# work or an exception is raised the function will simply return 1.
|
62
|
-
#
|
63
|
-
# @return [Integer] number physical processor cores on the current system
|
64
|
-
#
|
65
|
-
# @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
|
66
|
-
#
|
67
|
-
# @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
|
68
|
-
# @see http://www.unix.com/man-page/osx/1/HWPREFS/
|
69
|
-
# @see http://linux.die.net/man/8/sysctl
|
70
|
-
def physical_processor_count
|
71
|
-
@physical_processor_count.value
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def compute_processor_count
|
77
|
-
if Concurrent.on_jruby?
|
78
|
-
java.lang.Runtime.getRuntime.availableProcessors
|
79
|
-
else
|
80
|
-
os_name = RbConfig::CONFIG["target_os"]
|
81
|
-
if os_name =~ /mingw|mswin/
|
82
|
-
require 'win32ole'
|
83
|
-
result = WIN32OLE.connect("winmgmts://").ExecQuery(
|
84
|
-
"select NumberOfLogicalProcessors from Win32_Processor")
|
85
|
-
result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
|
86
|
-
elsif File.readable?("/proc/cpuinfo") && (cpuinfo_count = IO.read("/proc/cpuinfo").scan(/^processor/).size) > 0
|
87
|
-
cpuinfo_count
|
88
|
-
elsif File.executable?("/usr/bin/nproc")
|
89
|
-
IO.popen("/usr/bin/nproc --all", &:read).to_i
|
90
|
-
elsif File.executable?("/usr/bin/hwprefs")
|
91
|
-
IO.popen("/usr/bin/hwprefs thread_count", &:read).to_i
|
92
|
-
elsif File.executable?("/usr/sbin/psrinfo")
|
93
|
-
IO.popen("/usr/sbin/psrinfo", &:read).scan(/^.*on-*line/).size
|
94
|
-
elsif File.executable?("/usr/sbin/ioscan")
|
95
|
-
IO.popen("/usr/sbin/ioscan -kC processor", &:read).scan(/^.*processor/).size
|
96
|
-
elsif File.executable?("/usr/sbin/pmcycles")
|
97
|
-
IO.popen("/usr/sbin/pmcycles -m", &:read).count("\n")
|
98
|
-
elsif File.executable?("/usr/sbin/lsdev")
|
99
|
-
IO.popen("/usr/sbin/lsdev -Cc processor -S 1", &:read).count("\n")
|
100
|
-
elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
|
101
|
-
IO.popen("/usr/sbin/sysconf NPROC_ONLN", &:read).to_i
|
102
|
-
elsif File.executable?("/usr/sbin/sysctl")
|
103
|
-
IO.popen("/usr/sbin/sysctl -n hw.ncpu", &:read).to_i
|
104
|
-
elsif File.executable?("/sbin/sysctl")
|
105
|
-
IO.popen("/sbin/sysctl -n hw.ncpu", &:read).to_i
|
106
|
-
else
|
107
|
-
# TODO (pitr-ch 05-Nov-2016): warn about failures
|
108
|
-
1
|
109
|
-
end
|
110
|
-
end
|
111
|
-
rescue
|
112
|
-
return 1
|
113
|
-
end
|
114
|
-
|
115
|
-
def compute_physical_processor_count
|
116
|
-
ppc = case RbConfig::CONFIG["target_os"]
|
117
|
-
when /darwin1/
|
118
|
-
IO.popen("/usr/sbin/sysctl -n hw.physicalcpu", &:read).to_i
|
119
|
-
when /linux/
|
120
|
-
cores = {} # unique physical ID / core ID combinations
|
121
|
-
phy = 0
|
122
|
-
IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
|
123
|
-
if ln.start_with?("physical")
|
124
|
-
phy = ln[/\d+/]
|
125
|
-
elsif ln.start_with?("core")
|
126
|
-
cid = phy + ":" + ln[/\d+/]
|
127
|
-
cores[cid] = true if not cores[cid]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
cores.count
|
131
|
-
when /mswin|mingw/
|
132
|
-
require 'win32ole'
|
133
|
-
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
134
|
-
"select NumberOfCores from Win32_Processor")
|
135
|
-
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
136
|
-
else
|
137
|
-
processor_count
|
138
|
-
end
|
139
|
-
# fall back to logical count if physical info is invalid
|
140
|
-
ppc > 0 ? ppc : processor_count
|
141
|
-
rescue
|
142
|
-
return 1
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# create the default ProcessorCounter on load
|
148
|
-
@processor_counter = Utility::ProcessorCounter.new
|
149
|
-
singleton_class.send :attr_reader, :processor_counter
|
150
|
-
|
151
|
-
def self.processor_count
|
152
|
-
processor_counter.processor_count
|
153
|
-
end
|
154
|
-
|
155
|
-
def self.physical_processor_count
|
156
|
-
processor_counter.physical_processor_count
|
157
|
-
end
|
158
|
-
end
|
data/lib/concurrent/version.rb
DELETED
data/lib/concurrent-ruby.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require_relative "./concurrent"
|
File without changes
|
File without changes
|
data/lib/{concurrent → concurrent-ruby/concurrent}/collection/java_non_concurrent_priority_queue.rb
RENAMED
File without changes
|
data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/atomic_reference_map_backend.rb
RENAMED
File without changes
|
data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/synchronized_map_backend.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serialized_execution_delegator.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|