File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
lib/concurrent-ruby/concurrent Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,13 @@ module Concurrent
23
23
# @!macro internal_implementation_note
24
24
SetImplementation = case
25
25
when Concurrent . on_cruby?
26
- # Because MRI never runs code in parallel, the existing
27
- # non-thread-safe structures should usually work fine.
28
- ::Set
26
+ require 'monitor'
27
+ require 'concurrent/thread_safe/util/data_structures'
28
+
29
+ class CRubySet < ::Set
30
+ end
31
+ ThreadSafe ::Util . make_synchronized_on_cruby Concurrent ::CRubySet
32
+ CRubySet
29
33
30
34
when Concurrent . on_jruby?
31
35
require 'jruby/synchronized'
Original file line number Diff line number Diff line change @@ -12,6 +12,25 @@ def self.synchronized(object, &block)
12
12
module Concurrent
13
13
module ThreadSafe
14
14
module Util
15
+ def self . make_synchronized_on_cruby ( klass )
16
+ klass . class_eval do
17
+ def initialize ( *args , &block )
18
+ @_monitor = Monitor . new
19
+ super
20
+ end
21
+ end
22
+
23
+ klass . superclass . instance_methods ( false ) . each do |method |
24
+ klass . class_eval <<-RUBY , __FILE__ , __LINE__ + 1
25
+ def #{ method } (*args)
26
+ monitor = @_monitor
27
+ monitor or raise("BUG: Internal monitor was not properly initialized. Please report this to the concurrent-ruby developers.")
28
+ monitor.synchronize { super }
29
+ end
30
+ RUBY
31
+ end
32
+ end
33
+
15
34
def self . make_synchronized_on_rbx ( klass )
16
35
klass . class_eval do
17
36
private
You can’t perform that action at this time.
0 commit comments