class Garcon::MutexAtomicBoolean
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.
Public Class Methods
new(initial = false)
click to toggle source
Creates a new ‘AtomicBoolean` with the given initial value.
@param [Boolean] initial
the initial value
@api public
# File lib/garcon/task/atomic_boolean.rb, line 34 def initialize(initial = false) @value = !!initial @mutex = Mutex.new end
Public Instance Methods
false?()
click to toggle source
Is the current value ‘false`
@return [Boolean]
True if the current value is `false`, else false
@api public
# File lib/garcon/task/atomic_boolean.rb, line 88 def false? @mutex.lock !@value ensure @mutex.unlock end
make_false()
click to toggle source
Explicitly sets the value to false.
@return [Boolean]
True is value has changed, otherwise false
@api public
# File lib/garcon/task/atomic_boolean.rb, line 116 def make_false @mutex.lock old = @value @value = false old ensure @mutex.unlock end
make_true()
click to toggle source
Explicitly sets the value to true.
@return [Boolean]
True is value has changed, otherwise false
@api public
# File lib/garcon/task/atomic_boolean.rb, line 101 def make_true @mutex.lock old = @value @value = true !old ensure @mutex.unlock end
true?()
click to toggle source
Is the current value ‘true`
@return [Boolean]
True if the current value is `true`, else false
@api public
# File lib/garcon/task/atomic_boolean.rb, line 75 def true? @mutex.lock @value ensure @mutex.unlock end
value()
click to toggle source
Retrieves the current ‘Boolean` value.
@return [Boolean]
the current value
@api public
# File lib/garcon/task/atomic_boolean.rb, line 45 def value @mutex.lock @value ensure @mutex.unlock end
value=(value)
click to toggle source
Explicitly sets the value.
@param [Boolean] value
the new value to be set
@return [Boolean]
the current value
@api public
# File lib/garcon/task/atomic_boolean.rb, line 61 def value=(value) @mutex.lock @value = !!value @value ensure @mutex.unlock end