concurrent-ruby 0.7.0.rc1-x86-mingw32 → 0.7.0.rc2-x86-mingw32

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.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +3 -2
  3. data/ext/concurrent_ruby_ext/atomic_boolean.c +48 -0
  4. data/ext/concurrent_ruby_ext/atomic_boolean.h +16 -0
  5. data/ext/concurrent_ruby_ext/atomic_fixnum.c +50 -0
  6. data/ext/concurrent_ruby_ext/atomic_fixnum.h +13 -0
  7. data/ext/concurrent_ruby_ext/atomic_reference.c +44 -44
  8. data/ext/concurrent_ruby_ext/atomic_reference.h +8 -0
  9. data/ext/concurrent_ruby_ext/rb_concurrent.c +32 -3
  10. data/ext/concurrent_ruby_ext/ruby_193_compatible.h +28 -0
  11. data/lib/1.9/concurrent_ruby_ext.so +0 -0
  12. data/lib/2.0/concurrent_ruby_ext.so +0 -0
  13. data/lib/concurrent.rb +2 -1
  14. data/lib/concurrent/actor.rb +104 -0
  15. data/lib/concurrent/{actress → actor}/ad_hoc.rb +2 -3
  16. data/lib/concurrent/actor/behaviour.rb +70 -0
  17. data/lib/concurrent/actor/behaviour/abstract.rb +48 -0
  18. data/lib/concurrent/actor/behaviour/awaits.rb +21 -0
  19. data/lib/concurrent/actor/behaviour/buffer.rb +54 -0
  20. data/lib/concurrent/actor/behaviour/errors_on_unknown_message.rb +12 -0
  21. data/lib/concurrent/actor/behaviour/executes_context.rb +18 -0
  22. data/lib/concurrent/actor/behaviour/linking.rb +42 -0
  23. data/lib/concurrent/actor/behaviour/pausing.rb +77 -0
  24. data/lib/concurrent/actor/behaviour/removes_child.rb +16 -0
  25. data/lib/concurrent/actor/behaviour/sets_results.rb +36 -0
  26. data/lib/concurrent/actor/behaviour/supervised.rb +58 -0
  27. data/lib/concurrent/actor/behaviour/supervising.rb +34 -0
  28. data/lib/concurrent/actor/behaviour/terminates_children.rb +13 -0
  29. data/lib/concurrent/actor/behaviour/termination.rb +54 -0
  30. data/lib/concurrent/actor/context.rb +153 -0
  31. data/lib/concurrent/actor/core.rb +213 -0
  32. data/lib/concurrent/actor/default_dead_letter_handler.rb +9 -0
  33. data/lib/concurrent/{actress → actor}/envelope.rb +1 -1
  34. data/lib/concurrent/actor/errors.rb +27 -0
  35. data/lib/concurrent/actor/internal_delegations.rb +49 -0
  36. data/lib/concurrent/{actress/core_delegations.rb → actor/public_delegations.rb} +11 -13
  37. data/lib/concurrent/{actress → actor}/reference.rb +25 -8
  38. data/lib/concurrent/actor/root.rb +37 -0
  39. data/lib/concurrent/{actress → actor}/type_check.rb +1 -1
  40. data/lib/concurrent/actor/utills.rb +7 -0
  41. data/lib/concurrent/actor/utils/broadcast.rb +36 -0
  42. data/lib/concurrent/actress.rb +2 -224
  43. data/lib/concurrent/agent.rb +10 -12
  44. data/lib/concurrent/atomic.rb +32 -1
  45. data/lib/concurrent/atomic/atomic_boolean.rb +55 -13
  46. data/lib/concurrent/atomic/atomic_fixnum.rb +54 -16
  47. data/lib/concurrent/atomic/synchronization.rb +51 -0
  48. data/lib/concurrent/atomic/thread_local_var.rb +15 -50
  49. data/lib/concurrent/atomic_reference/mutex_atomic.rb +1 -1
  50. data/lib/concurrent/atomic_reference/ruby.rb +15 -0
  51. data/lib/concurrent/atomics.rb +1 -0
  52. data/lib/concurrent/channel/unbuffered_channel.rb +2 -1
  53. data/lib/concurrent/configuration.rb +6 -3
  54. data/lib/concurrent/dataflow.rb +20 -3
  55. data/lib/concurrent/delay.rb +23 -31
  56. data/lib/concurrent/executor/executor.rb +7 -2
  57. data/lib/concurrent/executor/timer_set.rb +1 -1
  58. data/lib/concurrent/future.rb +2 -1
  59. data/lib/concurrent/lazy_register.rb +58 -0
  60. data/lib/concurrent/options_parser.rb +4 -2
  61. data/lib/concurrent/promise.rb +2 -1
  62. data/lib/concurrent/scheduled_task.rb +6 -5
  63. data/lib/concurrent/tvar.rb +6 -10
  64. data/lib/concurrent/utility/processor_count.rb +4 -2
  65. data/lib/concurrent/version.rb +1 -1
  66. data/lib/concurrent_ruby_ext.so +0 -0
  67. metadata +37 -10
  68. data/lib/concurrent/actress/context.rb +0 -98
  69. data/lib/concurrent/actress/core.rb +0 -228
  70. data/lib/concurrent/actress/errors.rb +0 -14
@@ -1,3 +1,3 @@
1
1
  module Concurrent
2
- VERSION = '0.7.0.rc1'
2
+ VERSION = '0.7.0.rc2'
3
3
  end
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.rc1
4
+ version: 0.7.0.rc2
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Jerry D'Antonio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
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,22 +22,47 @@ 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/1.9/concurrent_ruby_ext.so
30
35
  - lib/2.0/concurrent_ruby_ext.so
31
36
  - lib/concurrent.rb
37
+ - lib/concurrent/actor.rb
38
+ - lib/concurrent/actor/ad_hoc.rb
39
+ - lib/concurrent/actor/behaviour.rb
40
+ - lib/concurrent/actor/behaviour/abstract.rb
41
+ - lib/concurrent/actor/behaviour/awaits.rb
42
+ - lib/concurrent/actor/behaviour/buffer.rb
43
+ - lib/concurrent/actor/behaviour/errors_on_unknown_message.rb
44
+ - lib/concurrent/actor/behaviour/executes_context.rb
45
+ - lib/concurrent/actor/behaviour/linking.rb
46
+ - lib/concurrent/actor/behaviour/pausing.rb
47
+ - lib/concurrent/actor/behaviour/removes_child.rb
48
+ - lib/concurrent/actor/behaviour/sets_results.rb
49
+ - lib/concurrent/actor/behaviour/supervised.rb
50
+ - lib/concurrent/actor/behaviour/supervising.rb
51
+ - lib/concurrent/actor/behaviour/terminates_children.rb
52
+ - lib/concurrent/actor/behaviour/termination.rb
53
+ - lib/concurrent/actor/context.rb
54
+ - lib/concurrent/actor/core.rb
55
+ - lib/concurrent/actor/default_dead_letter_handler.rb
56
+ - lib/concurrent/actor/envelope.rb
57
+ - lib/concurrent/actor/errors.rb
58
+ - lib/concurrent/actor/internal_delegations.rb
59
+ - lib/concurrent/actor/public_delegations.rb
60
+ - lib/concurrent/actor/reference.rb
61
+ - lib/concurrent/actor/root.rb
62
+ - lib/concurrent/actor/type_check.rb
63
+ - lib/concurrent/actor/utills.rb
64
+ - lib/concurrent/actor/utils/broadcast.rb
32
65
  - lib/concurrent/actress.rb
33
- - lib/concurrent/actress/ad_hoc.rb
34
- - lib/concurrent/actress/context.rb
35
- - lib/concurrent/actress/core.rb
36
- - lib/concurrent/actress/core_delegations.rb
37
- - lib/concurrent/actress/envelope.rb
38
- - lib/concurrent/actress/errors.rb
39
- - lib/concurrent/actress/reference.rb
40
- - lib/concurrent/actress/type_check.rb
41
66
  - lib/concurrent/agent.rb
42
67
  - lib/concurrent/async.rb
43
68
  - lib/concurrent/atomic.rb
@@ -49,6 +74,7 @@ files:
49
74
  - lib/concurrent/atomic/count_down_latch.rb
50
75
  - lib/concurrent/atomic/cyclic_barrier.rb
51
76
  - lib/concurrent/atomic/event.rb
77
+ - lib/concurrent/atomic/synchronization.rb
52
78
  - lib/concurrent/atomic/thread_local_var.rb
53
79
  - lib/concurrent/atomic_reference/concurrent_update_error.rb
54
80
  - lib/concurrent/atomic_reference/direct_update.rb
@@ -95,6 +121,7 @@ files:
95
121
  - lib/concurrent/executors.rb
96
122
  - lib/concurrent/future.rb
97
123
  - lib/concurrent/ivar.rb
124
+ - lib/concurrent/lazy_register.rb
98
125
  - lib/concurrent/logging.rb
99
126
  - lib/concurrent/mvar.rb
100
127
  - 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
@@ -1,14 +0,0 @@
1
- module Concurrent
2
- module Actress
3
- Error = Class.new(StandardError)
4
-
5
- class ActressTerminated < Error
6
- include TypeCheck
7
-
8
- def initialize(reference)
9
- Type! reference, Reference
10
- super reference.path
11
- end
12
- end
13
- end
14
- end