@@ -14,58 +14,6 @@ module TruffleRuby
1414
1515module Concurrent
1616
17- # @!macro atomic_reference
18- #
19- # An object reference that may be updated atomically. All read and write
20- # operations have java volatile semantic.
21- #
22- # @!macro thread_safe_variable_comparison
23- #
24- # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html
25- # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html
26- #
27- # @!method initialize(value = nil)
28- # @!macro atomic_reference_method_initialize
29- # @param [Object] value The initial value.
30- #
31- # @!method get
32- # @!macro atomic_reference_method_get
33- # Gets the current value.
34- # @return [Object] the current value
35- #
36- # @!method set(new_value)
37- # @!macro atomic_reference_method_set
38- # Sets to the given value.
39- # @param [Object] new_value the new value
40- # @return [Object] the new value
41- #
42- # @!method get_and_set(new_value)
43- # @!macro atomic_reference_method_get_and_set
44- # Atomically sets to the given value and returns the old value.
45- # @param [Object] new_value the new value
46- # @return [Object] the old value
47- #
48- # @!method compare_and_set(old_value, new_value)
49- # @!macro atomic_reference_method_compare_and_set
50- #
51- # Atomically sets the value to the given updated value if
52- # the current value == the expected value.
53- #
54- # @param [Object] old_value the expected value
55- # @param [Object] new_value the new value
56- #
57- # @return [Boolean] `true` if successful. A `false` return indicates
58- # that the actual value was not equal to the expected value.
59- #
60- # @!method update
61- # @!macro atomic_reference_method_update
62- #
63- # @!method try_update
64- # @!macro atomic_reference_method_try_update
65- #
66- # @!method try_update!
67- # @!macro atomic_reference_method_try_update!
68-
6917 # @!macro internal_implementation_note
7018 AtomicReferenceImplementation = case
7119 when Concurrent . on_cruby? && Concurrent . c_extensions_loaded?
@@ -98,7 +46,83 @@ class TruffleRubyAtomicReference < TruffleRuby::AtomicReference
9846 end
9947 private_constant :AtomicReferenceImplementation
10048
101- # @!macro atomic_reference
49+ # An object reference that may be updated atomically. All read and write
50+ # operations have java volatile semantic.
51+ #
52+ # @!macro thread_safe_variable_comparison
53+ #
54+ # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html
55+ # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html
56+ #
57+ # @!method initialize(value = nil)
58+ # @!macro atomic_reference_method_initialize
59+ # @param [Object] value The initial value.
60+ #
61+ # @!method get
62+ # @!macro atomic_reference_method_get
63+ # Gets the current value.
64+ # @return [Object] the current value
65+ #
66+ # @!method set(new_value)
67+ # @!macro atomic_reference_method_set
68+ # Sets to the given value.
69+ # @param [Object] new_value the new value
70+ # @return [Object] the new value
71+ #
72+ # @!method get_and_set(new_value)
73+ # @!macro atomic_reference_method_get_and_set
74+ # Atomically sets to the given value and returns the old value.
75+ # @param [Object] new_value the new value
76+ # @return [Object] the old value
77+ #
78+ # @!method compare_and_set(old_value, new_value)
79+ # @!macro atomic_reference_method_compare_and_set
80+ #
81+ # Atomically sets the value to the given updated value if
82+ # the current value == the expected value.
83+ #
84+ # @param [Object] old_value the expected value
85+ # @param [Object] new_value the new value
86+ #
87+ # @return [Boolean] `true` if successful. A `false` return indicates
88+ # that the actual value was not equal to the expected value.
89+ #
90+ # @!method update
91+ # Pass the current value to the given block, replacing it
92+ # with the block's result. May retry if the value changes
93+ # during the block's execution.
94+ #
95+ # @yield [Object] Calculate a new value for the atomic reference using
96+ # given (old) value
97+ # @yieldparam [Object] old_value the starting value of the atomic reference
98+ # @return [Object] the new value
99+ #
100+ # @!method try_update
101+ # Pass the current value to the given block, replacing it
102+ # with the block's result. Return nil if the update fails.
103+ #
104+ # @yield [Object] Calculate a new value for the atomic reference using
105+ # given (old) value
106+ # @yieldparam [Object] old_value the starting value of the atomic reference
107+ # @note This method was altered to avoid raising an exception by default.
108+ # Instead, this method now returns `nil` in case of failure. For more info,
109+ # please see: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
110+ # @return [Object] the new value, or nil if update failed
111+ #
112+ # @!method try_update!
113+ # Pass the current value to the given block, replacing it
114+ # with the block's result. Raise an exception if the update
115+ # fails.
116+ #
117+ # @yield [Object] Calculate a new value for the atomic reference using
118+ # given (old) value
119+ # @yieldparam [Object] old_value the starting value of the atomic reference
120+ # @note This behavior mimics the behavior of the original
121+ # `AtomicReference#try_update` API. The reason this was changed was to
122+ # avoid raising exceptions (which are inherently slow) by default. For more
123+ # info: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
124+ # @return [Object] the new value
125+ # @raise [Concurrent::ConcurrentUpdateError] if the update fails
102126 class AtomicReference < AtomicReferenceImplementation
103127
104128 # @return [String] Short string representation.
0 commit comments