99 end
1010
1111 specify :test_value do
12- atomic = described_class . new ( 0 )
12+ atomic = described_class . new ( 0 )
1313 atomic . value = 1
1414
1515 expect ( atomic . value ) . to eq 1
1818 specify :test_update do
1919 # use a number outside JRuby's fixnum cache range, to ensure identity is preserved
2020 atomic = described_class . new ( 1000 )
21- res = atomic . update { |v | v + 1 }
21+ res = atomic . update { |v | v + 1 }
2222
2323 expect ( atomic . value ) . to eq 1001
2424 expect ( res ) . to eq 1001
2727 specify :test_try_update do
2828 # use a number outside JRuby's fixnum cache range, to ensure identity is preserved
2929 atomic = described_class . new ( 1000 )
30- res = atomic . try_update { |v | v + 1 }
30+ res = atomic . try_update { |v | v + 1 }
3131
3232 expect ( atomic . value ) . to eq 1001
3333 expect ( res ) . to eq 1001
3636 specify :test_try_update_bang do
3737 # use a number outside JRuby's fixnum cache range, to ensure identity is preserved
3838 atomic = described_class . new ( 1000 )
39- res = atomic . try_update! { |v | v + 1 }
39+ res = atomic . try_update! { |v | v + 1 }
4040
4141 expect ( atomic . value ) . to eq 1001
4242 expect ( res ) . to eq 1001
4343 end
4444
4545 specify :test_swap do
4646 atomic = described_class . new ( 1000 )
47- res = atomic . swap ( 1001 )
47+ res = atomic . swap ( 1001 )
4848
4949 expect ( atomic . value ) . to eq 1001
5050 expect ( res ) . to eq 1000
5454 # use a number outside JRuby's fixnum cache range, to ensure identity is preserved
5555 atomic = described_class . new ( 1000 )
5656 expect (
57- # assigning within block exploits implementation detail for test
58- atomic . try_update { |v | atomic . value = 1001 ; v + 1 }
57+ # assigning within block exploits implementation detail for test
58+ atomic . try_update { |v | atomic . value = 1001 ; v + 1 }
5959 ) . to be_falsey
6060 end
6161
6464 atomic = described_class . new ( 1000 )
6565 expect {
6666 # assigning within block exploits implementation detail for test
67- atomic . try_update! { |v | atomic . value = 1001 ; v + 1 }
67+ atomic . try_update! { |v | atomic . value = 1001 ; v + 1 }
6868 } . to raise_error Concurrent ::ConcurrentUpdateError
6969 end
7070
7373 # use a number outside JRuby's fixnum cache range, to ensure identity is preserved
7474 atomic = described_class . new ( 1000 )
7575 # assigning within block exploits implementation detail for test
76- atomic . update { |v | tries += 1 ; atomic . value = 1001 ; v + 1 }
76+ atomic . update { |v | tries += 1 ; atomic . value = 1001 ; v + 1 }
7777
7878 expect ( tries ) . to eq 2
7979 end
8282 atomic = described_class . new ( 0 )
8383
8484 # 9-bit idempotent Fixnum (JRuby)
85- max_8 = 2 ** 256 - 1
86- min_8 = -( 2 ** 256 )
85+ max_8 = 2 ** 256 - 1
86+ min_8 = -( 2 ** 256 )
8787
8888 atomic . set ( max_8 )
8989 max_8 . upto ( max_8 + 2 ) do |i |
90- expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
90+ expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
9191 end
9292
9393 atomic . set ( min_8 )
9494 min_8 . downto ( min_8 - 2 ) do |i |
95- expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
95+ expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
9696 end
9797
9898 # 64-bit idempotent Fixnum (MRI, Rubinius)
99- max_64 = 2 ** 62 - 1
100- min_64 = -( 2 ** 62 )
99+ max_64 = 2 ** 62 - 1
100+ min_64 = -( 2 ** 62 )
101101
102102 atomic . set ( max_64 )
103103 max_64 . upto ( max_64 + 2 ) do |i |
104- expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
104+ expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
105105 end
106106
107107 atomic . set ( min_64 )
108108 min_64 . downto ( min_64 - 2 ) do |i |
109- expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
109+ expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
110110 end
111111
112112 ## 64-bit overflow into Bignum (JRuby)
113- max_64 = 2 ** 63 - 1
114- min_64 = ( -2 ** 63 )
113+ max_64 = 2 ** 63 - 1
114+ min_64 = ( -2 ** 63 )
115115
116116 atomic . set ( max_64 )
117117 max_64 . upto ( max_64 + 2 ) do |i |
118- expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
118+ expect ( atomic . compare_and_swap ( i , i + 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i + 1 } "
119119 end
120120
121121 atomic . set ( min_64 )
122122 min_64 . downto ( min_64 - 2 ) do |i |
123- expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
123+ expect ( atomic . compare_and_swap ( i , i - 1 ) ) . to be_truthy , "CAS failed for numeric #{ i } => #{ i - 1 } "
124124 end
125125
126126 # non-idempotent Float (JRuby, Rubinius, MRI < 2.0.0 or 32-bit)
127127 atomic . set ( 1.0 + 0.1 )
128128 expect ( atomic . compare_and_set ( 1.0 + 0.1 , 1.2 ) ) . to be_truthy , "CAS failed for #{ 1.0 + 0.1 } => 1.2"
129129
130130 # Bignum
131- atomic . set ( 2 ** 100 )
132- expect ( atomic . compare_and_set ( 2 ** 100 , 0 ) ) . to be_truthy , "CAS failed for #{ 2 ** 100 } => 0"
131+ atomic . set ( 2 ** 100 )
132+ expect ( atomic . compare_and_set ( 2 ** 100 , 0 ) ) . to be_truthy , "CAS failed for #{ 2 ** 100 } => 0"
133133
134134 # Rational
135135 require 'rational' unless '' . respond_to? :to_r
136- atomic . set ( Rational ( 1 , 3 ) )
137- expect ( atomic . compare_and_set ( Rational ( 1 , 3 ) , 0 ) ) . to be_truthy , "CAS failed for #{ Rational ( 1 , 3 ) } => 0"
136+ atomic . set ( Rational ( 1 , 3 ) )
137+ expect ( atomic . compare_and_set ( Rational ( 1 , 3 ) , 0 ) ) . to be_truthy , "CAS failed for #{ Rational ( 1 , 3 ) } => 0"
138138
139139 # Complex
140140 require 'complex' unless '' . respond_to? :to_c
141- atomic . set ( Complex ( 1 , 2 ) )
142- expect ( atomic . compare_and_set ( Complex ( 1 , 2 ) , 0 ) ) . to be_truthy , "CAS failed for #{ Complex ( 1 , 2 ) } => 0"
141+ atomic . set ( Complex ( 1 , 2 ) )
142+ expect ( atomic . compare_and_set ( Complex ( 1 , 2 ) , 0 ) ) . to be_truthy , "CAS failed for #{ Complex ( 1 , 2 ) } => 0"
143143 end
144144end
145145
@@ -162,53 +162,22 @@ module Concurrent
162162 end
163163
164164 if defined? Concurrent ::CAtomicReference
165- RSpec . describe CAtomicReference , ext : true do
165+ RSpec . describe CAtomicReference do
166166 it_should_behave_like :atomic_reference
167167 end
168- elsif defined? Concurrent ::JavaAtomicReference
168+ end
169+ if defined? Concurrent ::JavaAtomicReference
169170 RSpec . describe JavaAtomicReference do
170171 it_should_behave_like :atomic_reference
171172 end
172- elsif defined? Concurrent ::RbxAtomicReference
173+ end
174+ if defined? Concurrent ::RbxAtomicReference
173175 RSpec . describe RbxAtomicReference do
174176 it_should_behave_like :atomic_reference
175177 end
176178 end
177-
178- RSpec . describe AtomicReference do
179- if Concurrent . on_jruby?
180- it 'inherits from JavaAtomicReference' do
181- expect ( AtomicReference . ancestors ) . to include ( Concurrent ::JavaAtomicReference )
182- end
183- elsif Concurrent . allow_c_extensions?
184- it 'inherits from CAtomicReference' do
185- expect ( AtomicReference . ancestors ) . to include ( Concurrent ::CAtomicReference )
186- end
187- elsif Concurrent . on_rbx?
188- it 'inherits from RbxAtomicReference' do
189- expect ( AtomicReference . ancestors ) . to include ( Concurrent ::RbxAtomicReference )
190- end
191- else
192- it 'inherits from MutexAtomicReference' do
193- expect ( AtomicReference . ancestors ) . to include ( Concurrent ::MutexAtomicReference )
194- end
195- end
196- end
197-
198- RSpec . describe MutexAtomicReference do
199- it_should_behave_like :atomic_reference
200- end
201-
202- if defined? Concurrent ::CAtomicReference
203- RSpec . describe CAtomicReference , ext : true do
204- it_should_behave_like :atomic_reference
205- end
206- elsif defined? Concurrent ::JavaAtomicReference
207- RSpec . describe JavaAtomicReference do
208- it_should_behave_like :atomic_reference
209- end
210- elsif defined? Concurrent ::RbxAtomicReference
211- RSpec . describe RbxAtomicReference do
179+ if defined? Concurrent ::TruffleRubyAtomicReference
180+ RSpec . describe TruffleRubyAtomicReference do
212181 it_should_behave_like :atomic_reference
213182 end
214183 end
@@ -219,13 +188,17 @@ module Concurrent
219188 expect ( described_class . ancestors ) . to include ( Concurrent ::JavaAtomicReference )
220189 end
221190 elsif Concurrent . allow_c_extensions?
222- it 'inherits from CAtomicReference' , ext : true do
191+ it 'inherits from CAtomicReference' do
223192 expect ( described_class . ancestors ) . to include ( Concurrent ::CAtomicReference )
224193 end
225194 elsif Concurrent . on_rbx?
226195 it 'inherits from RbxAtomicReference' do
227196 expect ( described_class . ancestors ) . to include ( Concurrent ::RbxAtomicReference )
228197 end
198+ elsif Concurrent . on_truffleruby?
199+ it 'inherits from TruffleRubyAtomicReference' do
200+ expect ( described_class . ancestors ) . to include ( Concurrent ::TruffleRubyAtomicReference )
201+ end
229202 else
230203 it 'inherits from MutexAtomicReference' do
231204 expect ( described_class . ancestors ) . to include ( Concurrent ::MutexAtomicReference )
0 commit comments