1
1
module Concurrent
2
2
module Atomic
3
- # @!macro [attach] atomic_markable_reference
3
+ # An atomic reference which maintains an object reference along with a mark bit
4
+ # that can be updated atomically.
4
5
#
5
- # An atomic reference which maintains an object reference along with a mark bit
6
- # that can be updated atomically.
7
- #
8
- # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicMarkableReference.html
9
- # java.util.concurrent.atomic.AtomicMarkableReference
6
+ # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicMarkableReference.html
7
+ # java.util.concurrent.atomic.AtomicMarkableReference
10
8
class AtomicMarkableReference < ::Concurrent ::Synchronization ::Object
11
9
12
10
private ( *attr_atomic ( :reference ) )
13
11
14
- # @!macro [attach] atomic_markable_reference_method_initialize
15
12
def initialize ( value = nil , mark = false )
16
13
super ( )
17
14
self . reference = immutable_array ( value , mark )
18
15
end
19
16
20
- # @!macro [attach] atomic_markable_reference_method_compare_and_set
21
- #
22
- # Atomically sets the value and mark to the given updated value and
23
- # mark given both:
24
- # - the current value == the expected value &&
25
- # - the current mark == the expected mark
17
+ # Atomically sets the value and mark to the given updated value and
18
+ # mark given both:
19
+ # - the current value == the expected value &&
20
+ # - the current mark == the expected mark
26
21
#
27
- # @param [Object] expected_val the expected value
28
- # @param [Object] new_val the new value
29
- # @param [Boolean] expected_mark the expected mark
30
- # @param [Boolean] new_mark the new mark
22
+ # @param [Object] expected_val the expected value
23
+ # @param [Object] new_val the new value
24
+ # @param [Boolean] expected_mark the expected mark
25
+ # @param [Boolean] new_mark the new mark
31
26
#
32
- # @return [Boolean] `true` if successful. A `false` return indicates
33
- # that the actual value was not equal to the expected value or the
34
- # actual mark was not equal to the expected mark
27
+ # @return [Boolean] `true` if successful. A `false` return indicates
28
+ # that the actual value was not equal to the expected value or the
29
+ # actual mark was not equal to the expected mark
35
30
def compare_and_set ( expected_val , new_val , expected_mark , new_mark )
36
31
# Memoize a valid reference to the current AtomicReference for
37
32
# later comparison.
@@ -59,49 +54,39 @@ def compare_and_set(expected_val, new_val, expected_mark, new_mark)
59
54
end
60
55
alias_method :compare_and_swap , :compare_and_set
61
56
62
- # @!macro [attach] atomic_markable_reference_method_get
63
- #
64
- # Gets the current reference and marked values.
57
+ # Gets the current reference and marked values.
65
58
#
66
- # @return [Array] the current reference and marked values
59
+ # @return [Array] the current reference and marked values
67
60
def get
68
61
reference
69
62
end
70
63
71
- # @!macro [attach] atomic_markable_reference_method_value
64
+ # Gets the current value of the reference
72
65
#
73
- # Gets the current value of the reference
74
- #
75
- # @return [Object] the current value of the reference
66
+ # @return [Object] the current value of the reference
76
67
def value
77
68
reference [ 0 ]
78
69
end
79
70
80
- # @!macro [attach] atomic_markable_reference_method_mark
81
- #
82
- # Gets the current marked value
71
+ # Gets the current marked value
83
72
#
84
- # @return [Boolean] the current marked value
73
+ # @return [Boolean] the current marked value
85
74
def mark
86
75
reference [ 1 ]
87
76
end
88
77
alias_method :marked? , :mark
89
78
90
- # @!macro [attach] atomic_markable_reference_method_set
79
+ # _Unconditionally_ sets to the given value of both the reference and
80
+ # the mark.
91
81
#
92
- # _Unconditionally_ sets to the given value of both the reference and
93
- # the mark.
82
+ # @param [Object] new_val the new value
83
+ # @param [Boolean] new_mark the new mark
94
84
#
95
- # @param [Object] new_val the new value
96
- # @param [Boolean] new_mark the new mark
97
- #
98
- # @return [Array] both the new value and the new mark
85
+ # @return [Array] both the new value and the new mark
99
86
def set ( new_val , new_mark )
100
87
self . reference = immutable_array ( new_val , new_mark )
101
88
end
102
89
103
- # @!macro [attach] atomic_markable_reference_method_update
104
- #
105
90
# Pass the current value and marked state to the given block, replacing it
106
91
# with the block's results. May retry if the value changes during the
107
92
# block's execution.
@@ -123,8 +108,6 @@ def update
123
108
end
124
109
end
125
110
126
- # @!macro [attach] atomic_markable_reference_method_try_update!
127
- #
128
111
# Pass the current value to the given block, replacing it
129
112
# with the block's result. Raise an exception if the update
130
113
# fails.
@@ -151,8 +134,6 @@ def try_update!
151
134
immutable_array ( new_val , new_mark )
152
135
end
153
136
154
- # @!macro [attach] atomic_markable_reference_method_try_update
155
- #
156
137
# Pass the current value to the given block, replacing it with the
157
138
# block's result. Simply return nil if update fails.
158
139
#
0 commit comments