Skip to content

Commit 8de7cbd

Browse files
committed
Use supported TruffleRuby APIs
1 parent e6da3dd commit 8de7cbd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ concurrent-ruby:
66

77
* fixed documentation and README links
88
* fix Set for TruffleRuby and Rubinius
9+
* use properly supported TruffleRuby APIs
910

1011
concurrent-ruby-edge:
1112

lib/concurrent/atomic/atomic_reference.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
require 'concurrent/utility/engine'
33
require 'concurrent/atomic_reference/numeric_cas_wrapper'
44

5+
# Shim for TruffleRuby::AtomicReference
6+
if Concurrent.on_truffleruby? && !defined?(TruffleRuby::AtomicReference)
7+
module TruffleRuby
8+
AtomicReference = Truffle::AtomicReference
9+
end
10+
end
11+
512
module Concurrent
613

714
# Define update methods that use direct paths
@@ -155,8 +162,10 @@ class JavaAtomicReference
155162
end
156163
JavaAtomicReference
157164
when Concurrent.on_truffleruby?
158-
class TruffleRubyAtomicReference < Truffle::AtomicReference
165+
class TruffleRubyAtomicReference < TruffleRuby::AtomicReference
159166
include AtomicDirectUpdate
167+
alias_method :value, :get
168+
alias_method :value=, :set
160169
alias_method :compare_and_swap, :compare_and_set
161170
alias_method :swap, :get_and_set
162171
end

lib/concurrent/thread_safe/util/data_structures.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
require 'concurrent/thread_safe/util'
22

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+
312
module Concurrent
413
module ThreadSafe
514
module Util
@@ -44,8 +53,7 @@ def self.make_synchronized_on_truffleruby(klass)
4453
klass.superclass.instance_methods(false).each do |method|
4554
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
4655
def #{method}(*args, &block)
47-
# TODO (pitr-ch 01-Jul-2018): don't use internal TruffleRuby APIs
48-
Truffle::System.synchronized(self) { super(*args, &block) }
56+
TruffleRuby.synchronized(self) { super(*args, &block) }
4957
end
5058
RUBY
5159
end

0 commit comments

Comments
 (0)