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
Checks if the value is false.
-
#initialize(initial_value = false) ⇒ AtomicBoolean
constructor
Initializes a new AtomicBoolean.
-
#make_false ⇒ Boolean
Sets the value to false.
-
#make_true ⇒ Boolean
Sets the value to true.
-
#true? ⇒ Boolean
Checks if the value is true.
-
#value ⇒ Boolean
Gets the current value as a boolean.
Methods inherited from AtomicCounter
Constructor Details
#initialize(initial_value = false) ⇒ AtomicBoolean
Initializes a new AtomicBoolean
16 17 18 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 16 def initialize(initial_value = false) super(initial_value ? 1 : 0) end |
Instance Method Details
#false? ⇒ Boolean
Checks if the value is false
53 54 55 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 53 def false? @mutex.synchronize { @value == 0 } end |
#make_false ⇒ Boolean
Sets the value to false
38 39 40 41 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 38 def make_false @mutex.synchronize { @value = 0 } false end |
#make_true ⇒ Boolean
Sets the value to true
30 31 32 33 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 30 def make_true @mutex.synchronize { @value = 1 } true end |
#true? ⇒ Boolean
Checks if the value is true
46 47 48 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 46 def true? @mutex.synchronize { @value != 0 } end |
#value ⇒ Boolean
Gets the current value as a boolean
23 24 25 |
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 23 def value super != 0 end |