File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -75,24 +75,28 @@ def false?
75
75
#
76
76
# Explicitly sets the value to true.
77
77
#
78
- # @return [nil]
78
+ # @return [Boolean] true is value has changed, otherwise false
79
79
def make_true
80
80
@mutex . lock
81
+ old = @value
81
82
@value = true
82
83
@mutex . unlock
83
- nil
84
+
85
+ !old
84
86
end
85
87
86
88
# @!macro [attach] atomic_boolean_method_make_false
87
89
#
88
90
# Explicitly sets the value to false.
89
91
#
90
- # @return [nil]
92
+ # @return [Boolean] true is value has changed, otherwise false
91
93
def make_false
92
94
@mutex . lock
95
+ old = @value
93
96
@value = false
94
97
@mutex . unlock
95
- nil
98
+
99
+ old
96
100
end
97
101
end
98
102
@@ -131,12 +135,12 @@ def false?
131
135
132
136
# @!macro atomic_boolean_method_make_true
133
137
def make_true
134
- @atomic . set ( true )
138
+ @atomic . compareAndSet ( false , true )
135
139
end
136
140
137
141
# @!macro atomic_boolean_method_make_false
138
142
def make_false
139
- @atomic . set ( false )
143
+ @atomic . compareAndSet ( true , false )
140
144
end
141
145
end
142
146
Original file line number Diff line number Diff line change 75
75
76
76
describe '#make_true' do
77
77
78
- it 'makes a false value true and returns nil ' do
78
+ it 'makes a false value true and returns true ' do
79
79
subject = described_class . new ( false )
80
- subject . make_true . should be_nil
80
+ subject . make_true . should be_true
81
81
subject . value . should be_true
82
82
end
83
83
84
- it 'keeps a true value true and returns nil ' do
84
+ it 'keeps a true value true and returns false ' do
85
85
subject = described_class . new ( true )
86
- subject . make_true . should be_nil
86
+ subject . make_true . should be_false
87
87
subject . value . should be_true
88
88
end
89
89
end
90
90
91
91
describe '#make_false' do
92
92
93
- it 'makes a true value false and returns nil ' do
93
+ it 'makes a true value false and returns true ' do
94
94
subject = described_class . new ( true )
95
- subject . make_false . should be_nil
95
+ subject . make_false . should be_true
96
96
subject . value . should be_false
97
97
end
98
98
99
- it 'keeps a false value false and returns nil ' do
99
+ it 'keeps a false value false and returns false ' do
100
100
subject = described_class . new ( false )
101
- subject . make_false . should be_nil
101
+ subject . make_false . should be_false
102
102
subject . value . should be_false
103
103
end
104
104
end
You can’t perform that action at this time.
0 commit comments