Class: Shoryuken::Helpers::AtomicBoolean
- Inherits:
-
AtomicCounter
- Object
- AtomicCounter
- Shoryuken::Helpers::AtomicBoolean
- Defined in:
- lib/shoryuken/helpers/atomic_boolean.rb
Overview
A thread-safe boolean implementation using AtomicCounter as base. Drop-in replacement for Concurrent::AtomicBoolean without external dependencies. Uses 1 for true and 0 for false internally.
Instance Method Summary collapse
-
#false? ⇒ Boolean
Check if the value is false.
-
#initialize(initial_value = false) ⇒ AtomicBoolean
constructor
A new instance of AtomicBoolean.
-
#make_false ⇒ Object
Set the value to false.
-
#make_true ⇒ Object
Set the value to true.
-
#true? ⇒ Boolean
Check if the value is true.
-
#value ⇒ Object
Get the current value as boolean.
Methods inherited from AtomicCounter
Constructor Details
#initialize(initial_value = false) ⇒ AtomicBoolean
Returns a new instance of AtomicBoolean.
12 13 14 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 12 def initialize(initial_value = false) super(initial_value ? 1 : 0) end |
Instance Method Details
#false? ⇒ Boolean
Check if the value is false
39 40 41 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 39 def false? @mutex.synchronize { @value == 0 } end |
#make_false ⇒ Object
Set the value to false
28 29 30 31 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 28 def make_false @mutex.synchronize { @value = 0 } false end |
#make_true ⇒ Object
Set the value to true
22 23 24 25 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 22 def make_true @mutex.synchronize { @value = 1 } true end |
#true? ⇒ Boolean
Check if the value is true
34 35 36 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 34 def true? @mutex.synchronize { @value != 0 } end |
#value ⇒ Object
Get the current value as boolean
17 18 19 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 17 def value super != 0 end |