concurrent-ruby 1.2.2 → 1.3.1.pre
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/lib/concurrent-ruby/concurrent/array.rb +3 -3
- data/lib/concurrent-ruby/concurrent/collection/map/synchronized_map_backend.rb +23 -20
- data/lib/concurrent-ruby/concurrent/concurrent_ruby.jar +0 -0
- data/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb +4 -0
- data/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb +4 -7
- data/lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb +5 -0
- data/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb +7 -0
- data/lib/concurrent-ruby/concurrent/executor/timer_set.rb +6 -2
- data/lib/concurrent-ruby/concurrent/hash.rb +5 -3
- data/lib/concurrent-ruby/concurrent/map.rb +2 -2
- data/lib/concurrent-ruby/concurrent/promises.rb +33 -23
- data/lib/concurrent-ruby/concurrent/timer_task.rb +59 -9
- data/lib/concurrent-ruby/concurrent/utility/processor_counter.rb +65 -0
- data/lib/concurrent-ruby/concurrent/version.rb +1 -1
- metadata +4 -6
- data/lib/concurrent-ruby/concurrent/collection/map/atomic_reference_map_backend.rb +0 -927
- data/lib/concurrent-ruby/concurrent/thread_safe/util/cheap_lockable.rb +0 -81
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'concurrent/thread_safe/util'
|
2
|
-
require 'concurrent/thread_safe/util/volatile'
|
3
|
-
require 'concurrent/utility/engine'
|
4
|
-
|
5
|
-
module Concurrent
|
6
|
-
|
7
|
-
# @!visibility private
|
8
|
-
module ThreadSafe
|
9
|
-
|
10
|
-
# @!visibility private
|
11
|
-
module Util
|
12
|
-
|
13
|
-
# Provides a cheapest possible (mainly in terms of memory usage) +Mutex+
|
14
|
-
# with the +ConditionVariable+ bundled in.
|
15
|
-
#
|
16
|
-
# Usage:
|
17
|
-
# class A
|
18
|
-
# include CheapLockable
|
19
|
-
#
|
20
|
-
# def do_exlusively
|
21
|
-
# cheap_synchronize { yield }
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# def wait_for_something
|
25
|
-
# cheap_synchronize do
|
26
|
-
# cheap_wait until resource_available?
|
27
|
-
# do_something
|
28
|
-
# cheap_broadcast # wake up others
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# @!visibility private
|
34
|
-
module CheapLockable
|
35
|
-
private
|
36
|
-
if Concurrent.on_jruby?
|
37
|
-
# Use Java's native synchronized (this) { wait(); notifyAll(); } to avoid the overhead of the extra Mutex objects
|
38
|
-
require 'jruby'
|
39
|
-
|
40
|
-
def cheap_synchronize
|
41
|
-
JRuby.reference0(self).synchronized { yield }
|
42
|
-
end
|
43
|
-
|
44
|
-
def cheap_wait
|
45
|
-
JRuby.reference0(self).wait
|
46
|
-
end
|
47
|
-
|
48
|
-
def cheap_broadcast
|
49
|
-
JRuby.reference0(self).notify_all
|
50
|
-
end
|
51
|
-
else
|
52
|
-
require 'thread'
|
53
|
-
|
54
|
-
extend Volatile
|
55
|
-
attr_volatile :mutex
|
56
|
-
|
57
|
-
# Non-reentrant Mutex#syncrhonize
|
58
|
-
def cheap_synchronize
|
59
|
-
true until (my_mutex = mutex) || cas_mutex(nil, my_mutex = Mutex.new)
|
60
|
-
my_mutex.synchronize { yield }
|
61
|
-
end
|
62
|
-
|
63
|
-
# Releases this object's +cheap_synchronize+ lock and goes to sleep waiting for other threads to +cheap_broadcast+, reacquires the lock on wakeup.
|
64
|
-
# Must only be called in +cheap_broadcast+'s block.
|
65
|
-
def cheap_wait
|
66
|
-
conditional_variable = @conditional_variable ||= ConditionVariable.new
|
67
|
-
conditional_variable.wait(mutex)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Wakes up all threads waiting for this object's +cheap_synchronize+ lock.
|
71
|
-
# Must only be called in +cheap_broadcast+'s block.
|
72
|
-
def cheap_broadcast
|
73
|
-
if conditional_variable = @conditional_variable
|
74
|
-
conditional_variable.broadcast
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|