concurrent-ruby 0.7.0.rc1-x64-mingw32 → 0.7.0.rc2-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +3 -2
- data/ext/concurrent_ruby_ext/atomic_boolean.c +48 -0
- data/ext/concurrent_ruby_ext/atomic_boolean.h +16 -0
- data/ext/concurrent_ruby_ext/atomic_fixnum.c +50 -0
- data/ext/concurrent_ruby_ext/atomic_fixnum.h +13 -0
- data/ext/concurrent_ruby_ext/atomic_reference.c +44 -44
- data/ext/concurrent_ruby_ext/atomic_reference.h +8 -0
- data/ext/concurrent_ruby_ext/rb_concurrent.c +32 -3
- data/ext/concurrent_ruby_ext/ruby_193_compatible.h +28 -0
- data/lib/2.0/concurrent_ruby_ext.so +0 -0
- data/lib/concurrent.rb +2 -1
- data/lib/concurrent/actor.rb +104 -0
- data/lib/concurrent/{actress → actor}/ad_hoc.rb +2 -3
- data/lib/concurrent/actor/behaviour.rb +70 -0
- data/lib/concurrent/actor/behaviour/abstract.rb +48 -0
- data/lib/concurrent/actor/behaviour/awaits.rb +21 -0
- data/lib/concurrent/actor/behaviour/buffer.rb +54 -0
- data/lib/concurrent/actor/behaviour/errors_on_unknown_message.rb +12 -0
- data/lib/concurrent/actor/behaviour/executes_context.rb +18 -0
- data/lib/concurrent/actor/behaviour/linking.rb +42 -0
- data/lib/concurrent/actor/behaviour/pausing.rb +77 -0
- data/lib/concurrent/actor/behaviour/removes_child.rb +16 -0
- data/lib/concurrent/actor/behaviour/sets_results.rb +36 -0
- data/lib/concurrent/actor/behaviour/supervised.rb +58 -0
- data/lib/concurrent/actor/behaviour/supervising.rb +34 -0
- data/lib/concurrent/actor/behaviour/terminates_children.rb +13 -0
- data/lib/concurrent/actor/behaviour/termination.rb +54 -0
- data/lib/concurrent/actor/context.rb +153 -0
- data/lib/concurrent/actor/core.rb +213 -0
- data/lib/concurrent/actor/default_dead_letter_handler.rb +9 -0
- data/lib/concurrent/{actress → actor}/envelope.rb +1 -1
- data/lib/concurrent/actor/errors.rb +27 -0
- data/lib/concurrent/actor/internal_delegations.rb +49 -0
- data/lib/concurrent/{actress/core_delegations.rb → actor/public_delegations.rb} +11 -13
- data/lib/concurrent/{actress → actor}/reference.rb +25 -8
- data/lib/concurrent/actor/root.rb +37 -0
- data/lib/concurrent/{actress → actor}/type_check.rb +1 -1
- data/lib/concurrent/actor/utills.rb +7 -0
- data/lib/concurrent/actor/utils/broadcast.rb +36 -0
- data/lib/concurrent/actress.rb +2 -224
- data/lib/concurrent/agent.rb +10 -12
- data/lib/concurrent/atomic.rb +32 -1
- data/lib/concurrent/atomic/atomic_boolean.rb +55 -13
- data/lib/concurrent/atomic/atomic_fixnum.rb +54 -16
- data/lib/concurrent/atomic/synchronization.rb +51 -0
- data/lib/concurrent/atomic/thread_local_var.rb +15 -50
- data/lib/concurrent/atomic_reference/mutex_atomic.rb +1 -1
- data/lib/concurrent/atomic_reference/ruby.rb +15 -0
- data/lib/concurrent/atomics.rb +1 -0
- data/lib/concurrent/channel/unbuffered_channel.rb +2 -1
- data/lib/concurrent/configuration.rb +6 -3
- data/lib/concurrent/dataflow.rb +20 -3
- data/lib/concurrent/delay.rb +23 -31
- data/lib/concurrent/executor/executor.rb +7 -2
- data/lib/concurrent/executor/timer_set.rb +1 -1
- data/lib/concurrent/future.rb +2 -1
- data/lib/concurrent/lazy_register.rb +58 -0
- data/lib/concurrent/options_parser.rb +4 -2
- data/lib/concurrent/promise.rb +2 -1
- data/lib/concurrent/scheduled_task.rb +6 -5
- data/lib/concurrent/tvar.rb +6 -10
- data/lib/concurrent/utility/processor_count.rb +4 -2
- data/lib/concurrent/version.rb +1 -1
- data/lib/concurrent_ruby_ext.so +0 -0
- metadata +37 -10
- data/lib/concurrent/actress/context.rb +0 -98
- data/lib/concurrent/actress/core.rb +0 -228
- data/lib/concurrent/actress/errors.rb +0 -14
data/lib/concurrent/version.rb
CHANGED
data/lib/concurrent_ruby_ext.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concurrent-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.rc2
|
5
5
|
platform: x64-mingw32
|
6
6
|
authors:
|
7
7
|
- Jerry D'Antonio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ! " Modern concurrency tools including agents, futures, promises,
|
14
14
|
thread pools, actors, supervisors, and more.\n Inspired by Erlang, Clojure, Go,
|
@@ -22,21 +22,46 @@ extra_rdoc_files:
|
|
22
22
|
files:
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
25
|
+
- ext/concurrent_ruby_ext/atomic_boolean.c
|
26
|
+
- ext/concurrent_ruby_ext/atomic_boolean.h
|
27
|
+
- ext/concurrent_ruby_ext/atomic_fixnum.c
|
28
|
+
- ext/concurrent_ruby_ext/atomic_fixnum.h
|
25
29
|
- ext/concurrent_ruby_ext/atomic_reference.c
|
26
30
|
- ext/concurrent_ruby_ext/atomic_reference.h
|
27
31
|
- ext/concurrent_ruby_ext/extconf.rb
|
28
32
|
- ext/concurrent_ruby_ext/rb_concurrent.c
|
33
|
+
- ext/concurrent_ruby_ext/ruby_193_compatible.h
|
29
34
|
- lib/2.0/concurrent_ruby_ext.so
|
30
35
|
- lib/concurrent.rb
|
36
|
+
- lib/concurrent/actor.rb
|
37
|
+
- lib/concurrent/actor/ad_hoc.rb
|
38
|
+
- lib/concurrent/actor/behaviour.rb
|
39
|
+
- lib/concurrent/actor/behaviour/abstract.rb
|
40
|
+
- lib/concurrent/actor/behaviour/awaits.rb
|
41
|
+
- lib/concurrent/actor/behaviour/buffer.rb
|
42
|
+
- lib/concurrent/actor/behaviour/errors_on_unknown_message.rb
|
43
|
+
- lib/concurrent/actor/behaviour/executes_context.rb
|
44
|
+
- lib/concurrent/actor/behaviour/linking.rb
|
45
|
+
- lib/concurrent/actor/behaviour/pausing.rb
|
46
|
+
- lib/concurrent/actor/behaviour/removes_child.rb
|
47
|
+
- lib/concurrent/actor/behaviour/sets_results.rb
|
48
|
+
- lib/concurrent/actor/behaviour/supervised.rb
|
49
|
+
- lib/concurrent/actor/behaviour/supervising.rb
|
50
|
+
- lib/concurrent/actor/behaviour/terminates_children.rb
|
51
|
+
- lib/concurrent/actor/behaviour/termination.rb
|
52
|
+
- lib/concurrent/actor/context.rb
|
53
|
+
- lib/concurrent/actor/core.rb
|
54
|
+
- lib/concurrent/actor/default_dead_letter_handler.rb
|
55
|
+
- lib/concurrent/actor/envelope.rb
|
56
|
+
- lib/concurrent/actor/errors.rb
|
57
|
+
- lib/concurrent/actor/internal_delegations.rb
|
58
|
+
- lib/concurrent/actor/public_delegations.rb
|
59
|
+
- lib/concurrent/actor/reference.rb
|
60
|
+
- lib/concurrent/actor/root.rb
|
61
|
+
- lib/concurrent/actor/type_check.rb
|
62
|
+
- lib/concurrent/actor/utills.rb
|
63
|
+
- lib/concurrent/actor/utils/broadcast.rb
|
31
64
|
- lib/concurrent/actress.rb
|
32
|
-
- lib/concurrent/actress/ad_hoc.rb
|
33
|
-
- lib/concurrent/actress/context.rb
|
34
|
-
- lib/concurrent/actress/core.rb
|
35
|
-
- lib/concurrent/actress/core_delegations.rb
|
36
|
-
- lib/concurrent/actress/envelope.rb
|
37
|
-
- lib/concurrent/actress/errors.rb
|
38
|
-
- lib/concurrent/actress/reference.rb
|
39
|
-
- lib/concurrent/actress/type_check.rb
|
40
65
|
- lib/concurrent/agent.rb
|
41
66
|
- lib/concurrent/async.rb
|
42
67
|
- lib/concurrent/atomic.rb
|
@@ -48,6 +73,7 @@ files:
|
|
48
73
|
- lib/concurrent/atomic/count_down_latch.rb
|
49
74
|
- lib/concurrent/atomic/cyclic_barrier.rb
|
50
75
|
- lib/concurrent/atomic/event.rb
|
76
|
+
- lib/concurrent/atomic/synchronization.rb
|
51
77
|
- lib/concurrent/atomic/thread_local_var.rb
|
52
78
|
- lib/concurrent/atomic_reference/concurrent_update_error.rb
|
53
79
|
- lib/concurrent/atomic_reference/direct_update.rb
|
@@ -94,6 +120,7 @@ files:
|
|
94
120
|
- lib/concurrent/executors.rb
|
95
121
|
- lib/concurrent/future.rb
|
96
122
|
- lib/concurrent/ivar.rb
|
123
|
+
- lib/concurrent/lazy_register.rb
|
97
124
|
- lib/concurrent/logging.rb
|
98
125
|
- lib/concurrent/mvar.rb
|
99
126
|
- lib/concurrent/obligation.rb
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
module Actress
|
3
|
-
|
4
|
-
# This module is used to define actors. It can be included in any class,
|
5
|
-
# only requirement is to override {Context#on_message} method.
|
6
|
-
# @example ping
|
7
|
-
# class Ping
|
8
|
-
# include Context
|
9
|
-
# def on_message(message)
|
10
|
-
# message
|
11
|
-
# end
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# Ping.spawn(:ping1).ask(:m).value #=> :m
|
15
|
-
module Context
|
16
|
-
include TypeCheck
|
17
|
-
include CoreDelegations
|
18
|
-
|
19
|
-
attr_reader :core
|
20
|
-
|
21
|
-
# @abstract override to define Actor's behaviour
|
22
|
-
# @param [Object] message
|
23
|
-
# @return [Object] a result which will be used to set the IVar supplied to Reference#ask
|
24
|
-
# @note self should not be returned (or sent to other actors), {#reference} should be used
|
25
|
-
# instead
|
26
|
-
def on_message(message)
|
27
|
-
raise NotImplementedError
|
28
|
-
end
|
29
|
-
|
30
|
-
# @api private
|
31
|
-
def on_envelope(envelope)
|
32
|
-
@envelope = envelope
|
33
|
-
on_message envelope.message
|
34
|
-
ensure
|
35
|
-
@envelope = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
# @see Actress.spawn
|
39
|
-
def spawn(*args, &block)
|
40
|
-
Actress.spawn(*args, &block)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @see Core#children
|
44
|
-
def children
|
45
|
-
core.children
|
46
|
-
end
|
47
|
-
|
48
|
-
# @see Core#terminate!
|
49
|
-
def terminate!
|
50
|
-
core.terminate!
|
51
|
-
end
|
52
|
-
|
53
|
-
# delegates to core.log
|
54
|
-
# @see Logging#log
|
55
|
-
def log(level, progname, message = nil, &block)
|
56
|
-
core.log(level, progname, message, &block)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def initialize_core(core)
|
62
|
-
@core = Type! core, Core
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [Envelope] current envelope, accessible inside #on_message processing
|
66
|
-
def envelope
|
67
|
-
@envelope or raise 'envelope not set'
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.included(base)
|
71
|
-
base.extend ClassMethods
|
72
|
-
super base
|
73
|
-
end
|
74
|
-
|
75
|
-
module ClassMethods
|
76
|
-
# behaves as {Concurrent::Actress.spawn} but class_name is auto-inserted based on receiver
|
77
|
-
def spawn(name_or_opts, *args, &block)
|
78
|
-
Actress.spawn spawn_optionify(name_or_opts, *args), &block
|
79
|
-
end
|
80
|
-
|
81
|
-
# behaves as {Concurrent::Actress.spawn!} but class_name is auto-inserted based on receiver
|
82
|
-
def spawn!(name_or_opts, *args, &block)
|
83
|
-
Actress.spawn! spawn_optionify(name_or_opts, *args), &block
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def spawn_optionify(name_or_opts, *args)
|
89
|
-
if name_or_opts.is_a? Hash
|
90
|
-
name_or_opts.merge class: self
|
91
|
-
else
|
92
|
-
{ class: self, name: name_or_opts, args: args }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
module Actress
|
3
|
-
|
4
|
-
require 'set'
|
5
|
-
|
6
|
-
# Core of the actor
|
7
|
-
# @note Whole class should be considered private. An user should use {Context}s and {Reference}s only.
|
8
|
-
# @note devel: core should not block on anything, e.g. it cannot wait on children to terminate
|
9
|
-
# that would eat up all threads in task pool and deadlock
|
10
|
-
class Core
|
11
|
-
include TypeCheck
|
12
|
-
include Concurrent::Logging
|
13
|
-
|
14
|
-
# @!attribute [r] reference
|
15
|
-
# @return [Reference] reference to this actor which can be safely passed around
|
16
|
-
# @!attribute [r] name
|
17
|
-
# @return [String] the name of this instance, it should be uniq (not enforced right now)
|
18
|
-
# @!attribute [r] path
|
19
|
-
# @return [String] a path of this actor. It is used for easier orientation and logging.
|
20
|
-
# Path is constructed recursively with: `parent.path + self.name` up to a {Actress.root},
|
21
|
-
# e.g. `/an_actor/its_child`.
|
22
|
-
# (It will also probably form a supervision path (failures will be reported up to parents)
|
23
|
-
# in future versions.)
|
24
|
-
# @!attribute [r] executor
|
25
|
-
# @return [Executor] which is used to process messages
|
26
|
-
# @!attribute [r] terminated
|
27
|
-
# @return [Event] event which will become set when actor is terminated.
|
28
|
-
# @!attribute [r] actor_class
|
29
|
-
# @return [Context] a class including {Context} representing Actor's behaviour
|
30
|
-
attr_reader :reference, :name, :path, :executor, :terminated, :actor_class
|
31
|
-
|
32
|
-
# @option opts [String] name
|
33
|
-
# @option opts [Reference, nil] parent of an actor spawning this one
|
34
|
-
# @option opts [Context] actor_class a class to be instantiated defining Actor's behaviour
|
35
|
-
# @option opts [Array<Object>] args arguments for actor_class instantiation
|
36
|
-
# @option opts [Executor] executor, default is `Concurrent.configuration.global_task_pool`
|
37
|
-
# @option opts [IVar, nil] initialized, if present it'll be set or failed after {Context} initialization
|
38
|
-
# @option opts [Proc, nil] logger a proc accepting (level, progname, message = nil, &block) params,
|
39
|
-
# can be used to hook actor instance to any logging system
|
40
|
-
# @param [Proc] block for class instantiation
|
41
|
-
def initialize(opts = {}, &block)
|
42
|
-
@mailbox = Array.new
|
43
|
-
@serialized_execution = SerializedExecution.new
|
44
|
-
# noinspection RubyArgCount
|
45
|
-
@terminated = Event.new
|
46
|
-
@executor = Type! opts.fetch(:executor, Concurrent.configuration.global_task_pool), Executor
|
47
|
-
@children = Set.new
|
48
|
-
@reference = Reference.new self
|
49
|
-
@name = (Type! opts.fetch(:name), String, Symbol).to_s
|
50
|
-
@actor = Concurrent::Atomic.new
|
51
|
-
|
52
|
-
parent = opts[:parent]
|
53
|
-
@parent_core = (Type! parent, Reference, NilClass) && parent.send(:core)
|
54
|
-
if @parent_core.nil? && @name != '/'
|
55
|
-
raise 'only root has no parent'
|
56
|
-
end
|
57
|
-
|
58
|
-
@path = @parent_core ? File.join(@parent_core.path, @name) : @name
|
59
|
-
@logger = opts[:logger]
|
60
|
-
|
61
|
-
@parent_core.add_child reference if @parent_core
|
62
|
-
|
63
|
-
@actor_class = actor_class = Child! opts.fetch(:class), Context
|
64
|
-
args = opts.fetch(:args, [])
|
65
|
-
initialized = Type! opts[:initialized], IVar, NilClass
|
66
|
-
|
67
|
-
schedule_execution do
|
68
|
-
begin
|
69
|
-
@actor.value = actor_class.new(*args, &block).
|
70
|
-
tap { |a| a.send :initialize_core, self }
|
71
|
-
initialized.set true if initialized
|
72
|
-
rescue => ex
|
73
|
-
log ERROR, ex
|
74
|
-
terminate!
|
75
|
-
initialized.fail ex if initialized
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# @return [Reference, nil] of parent actor
|
81
|
-
def parent
|
82
|
-
@parent_core && @parent_core.reference
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [Array<Reference>] of children actors
|
86
|
-
def children
|
87
|
-
guard!
|
88
|
-
@children.to_a
|
89
|
-
end
|
90
|
-
|
91
|
-
# @api private
|
92
|
-
def add_child(child)
|
93
|
-
guard!
|
94
|
-
Type! child, Reference
|
95
|
-
@children.add child
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
|
99
|
-
# @api private
|
100
|
-
def remove_child(child)
|
101
|
-
schedule_execution do
|
102
|
-
Type! child, Reference
|
103
|
-
@children.delete child
|
104
|
-
end
|
105
|
-
nil
|
106
|
-
end
|
107
|
-
|
108
|
-
# is executed by Reference scheduling processing of new messages
|
109
|
-
# can be called from other alternative Reference implementations
|
110
|
-
# @param [Envelope] envelope
|
111
|
-
def on_envelope(envelope)
|
112
|
-
schedule_execution do
|
113
|
-
if terminated?
|
114
|
-
reject_envelope envelope
|
115
|
-
else
|
116
|
-
@mailbox.push envelope
|
117
|
-
end
|
118
|
-
process_envelopes?
|
119
|
-
end
|
120
|
-
nil
|
121
|
-
end
|
122
|
-
|
123
|
-
# @note Actor rejects envelopes when terminated.
|
124
|
-
# @return [true, false] if actor is terminated
|
125
|
-
def terminated?
|
126
|
-
@terminated.set?
|
127
|
-
end
|
128
|
-
|
129
|
-
# Terminates the actor. Any Envelope received after termination is rejected.
|
130
|
-
# Terminates all its children, does not wait until they are terminated.
|
131
|
-
def terminate!
|
132
|
-
guard!
|
133
|
-
return nil if terminated?
|
134
|
-
|
135
|
-
@children.each do |ch|
|
136
|
-
ch.send(:core).tap { |core| core.send(:schedule_execution) { core.terminate! } }
|
137
|
-
end
|
138
|
-
|
139
|
-
@terminated.set
|
140
|
-
|
141
|
-
@parent_core.remove_child reference if @parent_core
|
142
|
-
@mailbox.each do |envelope|
|
143
|
-
reject_envelope envelope
|
144
|
-
log DEBUG, "rejected #{envelope.message} from #{envelope.sender_path}"
|
145
|
-
end
|
146
|
-
@mailbox.clear
|
147
|
-
|
148
|
-
nil
|
149
|
-
end
|
150
|
-
|
151
|
-
# @api private
|
152
|
-
# ensures that we are inside of the executor
|
153
|
-
def guard!
|
154
|
-
unless Actress.current == reference
|
155
|
-
raise "can be called only inside actor #{reference} but was #{Actress.current}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
private
|
160
|
-
|
161
|
-
# Ensures that only one envelope processing is scheduled with #schedule_execution,
|
162
|
-
# this allows other scheduled blocks to be executed before next envelope processing.
|
163
|
-
# Simply put this ensures that Core is still responsive to internal calls (like add_child)
|
164
|
-
# even though the Actor is flooded with messages.
|
165
|
-
def process_envelopes?
|
166
|
-
unless @mailbox.empty? || @receive_envelope_scheduled
|
167
|
-
@receive_envelope_scheduled = true
|
168
|
-
schedule_execution { receive_envelope }
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# @return [Context]
|
173
|
-
def actor
|
174
|
-
@actor.value
|
175
|
-
end
|
176
|
-
|
177
|
-
# Processes single envelope, calls #process_envelopes? at the end to ensure next envelope
|
178
|
-
# scheduling.
|
179
|
-
def receive_envelope
|
180
|
-
envelope = @mailbox.shift
|
181
|
-
|
182
|
-
if terminated?
|
183
|
-
reject_envelope envelope
|
184
|
-
log FATAL, "this should not be happening #{caller[0]}"
|
185
|
-
end
|
186
|
-
|
187
|
-
log DEBUG, "received #{envelope.message} from #{envelope.sender_path}"
|
188
|
-
|
189
|
-
result = actor.on_envelope envelope
|
190
|
-
envelope.ivar.set result unless envelope.ivar.nil?
|
191
|
-
|
192
|
-
nil
|
193
|
-
rescue => error
|
194
|
-
log ERROR, error
|
195
|
-
terminate!
|
196
|
-
envelope.ivar.fail error unless envelope.ivar.nil?
|
197
|
-
ensure
|
198
|
-
@receive_envelope_scheduled = false
|
199
|
-
process_envelopes?
|
200
|
-
end
|
201
|
-
|
202
|
-
# Schedules blocks to be executed on executor sequentially,
|
203
|
-
# sets Actress.current
|
204
|
-
def schedule_execution
|
205
|
-
@serialized_execution.post(@executor) do
|
206
|
-
begin
|
207
|
-
Thread.current[:__current_actor__] = reference
|
208
|
-
yield
|
209
|
-
rescue => e
|
210
|
-
log FATAL, e
|
211
|
-
ensure
|
212
|
-
Thread.current[:__current_actor__] = nil
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
nil
|
217
|
-
end
|
218
|
-
|
219
|
-
def reject_envelope(envelope)
|
220
|
-
envelope.reject! ActressTerminated.new(reference)
|
221
|
-
end
|
222
|
-
|
223
|
-
def log(level, message = nil, &block)
|
224
|
-
super level, @path, message, &block
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|