Class: Concurrent::JavaAtomicBoolean

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(initial = false) ⇒ JavaAtomicBoolean

Returns a new instance of JavaAtomicBoolean.

Since:

  • 0.6.0



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

Returns:

Since:

  • 0.6.0



132
133
134
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 132

def false?
  !@atomic.get
end

#make_falseBoolean

Explicitly sets the value to false.

Returns:

  • true is value has changed, otherwise false

Since:

  • 0.6.0



142
143
144
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 142

def make_false
  @atomic.compareAndSet(true, false)
end

#make_trueBoolean

Explicitly sets the value to true.

Returns:

  • true is value has changed, otherwise false

Since:

  • 0.6.0



137
138
139
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 137

def make_true
  @atomic.compareAndSet(false, true)
end

#true?Boolean

Returns:

Since:

  • 0.6.0



127
128
129
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 127

def true?
  @atomic.get
end

#valueBoolean

Retrieves the current ‘Boolean` value.

Returns:

  • the current value

Since:

  • 0.6.0



116
117
118
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 116

def value
  @atomic.get
end

#value=(value) ⇒ Boolean

Explicitly sets the value.

Parameters:

  • the new value to be set

Returns:

  • the current value

Since:

  • 0.6.0



122
123
124
# File 'lib/concurrent/atomic/atomic_boolean.rb', line 122

def value=(value)
  @atomic.set(!!value)
end