1
+ require 'concurrent/atomic/mutex_atomic_boolean'
1
2
require 'concurrent/utility/native_extension_loader'
2
- require 'concurrent/synchronization'
3
3
4
4
module Concurrent
5
5
6
- # @!macro [attach] atomic_boolean
6
+ ###################################################################
7
+
8
+ # @!macro [new] atomic_boolean_method_initialize
7
9
#
8
- # A boolean value that can be updated atomically. Reads and writes to an atomic
9
- # boolean and thread-safe and guaranteed to succeed. Reads and writes may block
10
- # briefly but no explicit locking is required.
10
+ # Creates a new `AtomicBoolean` with the given initial value.
11
11
#
12
- # Testing with ruby 2.1.2
13
- # Testing with Concurrent::MutexAtomicBoolean...
14
- # 2.790000 0.000000 2.790000 ( 2.791454)
15
- # Testing with Concurrent::CAtomicBoolean...
16
- # 0.740000 0.000000 0.740000 ( 0.740206)
12
+ # @param [Boolean] initial the initial value
13
+
14
+ # @!macro [new] atomic_boolean_method_value_get
17
15
#
18
- # Testing with jruby 1.9.3
19
- # Testing with Concurrent::MutexAtomicBoolean...
20
- # 5.240000 2.520000 7.760000 ( 3.683000)
21
- # Testing with Concurrent::JavaAtomicBoolean...
22
- # 3.340000 0.010000 3.350000 ( 0.855000)
16
+ # Retrieves the current `Boolean` value.
23
17
#
24
- # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html java.util.concurrent.atomic.AtomicBoolean
18
+ # @return [Boolean] the current value
19
+
20
+ # @!macro [new] atomic_boolean_method_value_set
25
21
#
26
- # @!visibility private
22
+ # Explicitly sets the value.
27
23
#
28
- # @!macro internal_implementation_note
29
- class MutexAtomicBoolean < Synchronization ::Object
30
-
31
- # @!macro [attach] atomic_boolean_method_initialize
32
- #
33
- # Creates a new `AtomicBoolean` with the given initial value.
34
- #
35
- # @param [Boolean] initial the initial value
36
- def initialize ( initial = false )
37
- super ( )
38
- synchronize { ns_initialize ( initial ) }
39
- end
40
-
41
- # @!macro [attach] atomic_boolean_method_value_get
42
- #
43
- # Retrieves the current `Boolean` value.
44
- #
45
- # @return [Boolean] the current value
46
- def value
47
- synchronize { @value }
48
- end
49
-
50
- # @!macro [attach] atomic_boolean_method_value_set
51
- #
52
- # Explicitly sets the value.
53
- #
54
- # @param [Boolean] value the new value to be set
55
- #
56
- # @return [Boolean] the current value
57
- def value = ( value )
58
- synchronize { @value = !!value }
59
- end
60
-
61
- # @!macro [attach] atomic_boolean_method_true_question
62
- #
63
- # Is the current value `true`
64
- #
65
- # @return [Boolean] true if the current value is `true`, else false
66
- def true?
67
- synchronize { @value }
68
- end
24
+ # @param [Boolean] value the new value to be set
25
+ #
26
+ # @return [Boolean] the current value
69
27
70
- # @!macro [attach] atomic_boolean_method_false_question
71
- #
72
- # Is the current value `false`
73
- #
74
- # @return [Boolean] true if the current value is `false`, else false
75
- def false?
76
- synchronize { !@value }
77
- end
28
+ # @!macro [new] atomic_boolean_method_true_question
29
+ #
30
+ # Is the current value `true`
31
+ #
32
+ # @return [Boolean] true if the current value is `true`, else false
78
33
79
- # @!macro [attach] atomic_boolean_method_make_true
80
- #
81
- # Explicitly sets the value to true.
82
- #
83
- # @return [Boolean] true is value has changed, otherwise false
84
- def make_true
85
- synchronize { ns_make_value ( true ) }
86
- end
34
+ # @!macro [new] atomic_boolean_method_false_question
35
+ #
36
+ # Is the current value `false`
37
+ #
38
+ # @return [Boolean] true if the current value is `false`, else false
87
39
88
- # @!macro [attach] atomic_boolean_method_make_false
89
- #
90
- # Explicitly sets the value to false.
91
- #
92
- # @return [Boolean] true is value has changed, otherwise false
93
- def make_false
94
- synchronize { ns_make_value ( false ) }
95
- end
40
+ # @!macro [new] atomic_boolean_method_make_true
41
+ #
42
+ # Explicitly sets the value to true.
43
+ #
44
+ # @return [Boolean] true is value has changed, otherwise false
96
45
97
- protected
46
+ # @!macro [new] atomic_boolean_method_make_false
47
+ #
48
+ # Explicitly sets the value to false.
49
+ #
50
+ # @return [Boolean] true is value has changed, otherwise false
51
+
52
+ ###################################################################
98
53
99
- # @!visibility private
100
- def ns_initialize ( initial )
101
- @value = !!initial
102
- end
54
+ # @!macro [new] atomic_boolean_public_api
55
+ #
56
+ # @!method initialize(initial = false)
57
+ # @!macro atomic_boolean_method_initialize
58
+ #
59
+ # @!method value
60
+ # @!macro atomic_boolean_method_value_get
61
+ #
62
+ # @!method value=(value)
63
+ # @!macro atomic_boolean_method_value_set
64
+ #
65
+ # @!method true?
66
+ # @!macro atomic_boolean_method_true_question
67
+ #
68
+ # @!method false?
69
+ # @!macro atomic_boolean_method_false_question
70
+ #
71
+ # @!method make_true
72
+ # @!macro atomic_boolean_method_make_true
73
+ #
74
+ # @!method make_false
75
+ # @!macro atomic_boolean_method_make_false
103
76
104
- # @!visibility private
105
- def ns_make_value ( value )
106
- old = @value
107
- @value = value
108
- old != @value
109
- end
110
- end
77
+ ###################################################################
111
78
112
79
# @!visibility private
113
80
# @!macro internal_implementation_note
@@ -121,31 +88,27 @@ def ns_make_value(value)
121
88
end
122
89
private_constant :AtomicBooleanImplementation
123
90
124
- # @!macro atomic_boolean
91
+ # @!macro [attach] atomic_boolean
92
+ #
93
+ # A boolean value that can be updated atomically. Reads and writes to an atomic
94
+ # boolean and thread-safe and guaranteed to succeed. Reads and writes may block
95
+ # briefly but no explicit locking is required.
96
+ #
97
+ # Testing with ruby 2.1.2
98
+ # Testing with Concurrent::MutexAtomicBoolean...
99
+ # 2.790000 0.000000 2.790000 ( 2.791454)
100
+ # Testing with Concurrent::CAtomicBoolean...
101
+ # 0.740000 0.000000 0.740000 ( 0.740206)
102
+ #
103
+ # Testing with jruby 1.9.3
104
+ # Testing with Concurrent::MutexAtomicBoolean...
105
+ # 5.240000 2.520000 7.760000 ( 3.683000)
106
+ # Testing with Concurrent::JavaAtomicBoolean...
107
+ # 3.340000 0.010000 3.350000 ( 0.855000)
108
+ #
109
+ # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html java.util.concurrent.atomic.AtomicBoolean
125
110
#
126
- # @see Concurrent::MutexAtomicBoolean
111
+ # @!macro atomic_boolean_public_api
127
112
class AtomicBoolean < AtomicBooleanImplementation
128
-
129
- # @!method initialize(initial = false)
130
- # @!macro atomic_boolean_method_initialize
131
-
132
- # @!method value
133
- # @!macro atomic_boolean_method_value_get
134
-
135
- # @!method value=(value)
136
- # @!macro atomic_boolean_method_value_set
137
-
138
- # @!method true?
139
- # @!macro atomic_boolean_method_true_question
140
-
141
- # @!method false?
142
- # @!macro atomic_boolean_method_false_question
143
-
144
- # @!method make_true
145
- # @!macro atomic_boolean_method_make_true
146
-
147
- # @!method make_false
148
- # @!macro atomic_boolean_method_make_false
149
-
150
113
end
151
114
end
0 commit comments