Class: Concurrent::JavaAtomicBoolean
- Inherits:
-
Object
- Object
- Concurrent::JavaAtomicBoolean
- Defined in:
- lib/concurrent/atomic/atomic_boolean.rb
Overview
A boolean value that can be updated atomically. Reads and writes to an atomic boolean and thread-safe and guaranteed to succeed. Reads and writes may block briefly but no explicit locking is required.
Instance Method Summary collapse
- #false? ⇒ Boolean
-
#initialize(initial = false) ⇒ JavaAtomicBoolean
constructor
A new instance of JavaAtomicBoolean.
-
#make_false ⇒ Boolean
Explicitly sets the value to false.
-
#make_true ⇒ Boolean
Explicitly sets the value to true.
- #true? ⇒ Boolean
-
#value ⇒ Boolean
Retrieves the current ‘Boolean` value.
-
#value=(value) ⇒ Boolean
Explicitly sets the value.
Constructor Details
#initialize(initial = false) ⇒ JavaAtomicBoolean
Returns a new instance of JavaAtomicBoolean.
110 111 112 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 110 def initialize(initial = false) @atomic = java.util.concurrent.atomic.AtomicBoolean.new(!!initial) end |
Instance Method Details
#false? ⇒ Boolean
132 133 134 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 132 def false? !@atomic.get end |
#make_false ⇒ Boolean
Explicitly sets the value to false.
142 143 144 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 142 def make_false @atomic.compareAndSet(true, false) end |
#make_true ⇒ Boolean
Explicitly sets the value to true.
137 138 139 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 137 def make_true @atomic.compareAndSet(false, true) end |
#true? ⇒ Boolean
127 128 129 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 127 def true? @atomic.get end |
#value ⇒ Boolean
Retrieves the current ‘Boolean` value.
116 117 118 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 116 def value @atomic.get end |
#value=(value) ⇒ Boolean
Explicitly sets the value.
122 123 124 |
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 122 def value=(value) @atomic.set(!!value) end |