Skip to content

Commit 10ec86f

Browse files
authored
Merge pull request #765 from ruby-concurrency/truffleruby-api
Use supported TruffleRuby APIs
2 parents e6da3dd + 5975961 commit 10ec86f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ matrix:
1515
- name: TruffleRuby Latest
1616
rvm: system
1717
install:
18-
- export TRUFFLERUBY_VERSION=1.0.0-rc5
18+
- export TRUFFLERUBY_VERSION=1.0.0-rc7
1919
- curl -L https://github.com/oracle/truffleruby/releases/download/vm-$TRUFFLERUBY_VERSION/truffleruby-$TRUFFLERUBY_VERSION-linux-amd64.tar.gz | tar xz
2020
- export PATH="$PWD/truffleruby-$TRUFFLERUBY_VERSION-linux-amd64/bin:$PATH"
2121
- gem install bundler

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)