Class: Concurrent::MutexAtomicReference
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb |
Overview
**Private Implementation:** This abstraction is a private, internal implementation detail. It should never be used directly.
Class Method Summary
- .new(value = nil) ⇒ MutexAtomicReference constructor
Synchronization::SafeInitialization
- Extended
Instance Attribute Summary
-
#value
rw
Alias for #get.
-
#value=(new_value)
rw
Alias for #set.
Instance Method Summary
-
#_compare_and_set(old_value, new_value) ⇒ Boolean
Atomically sets the value to the given updated value if the current value == the expected value.
- #compare_and_swap
-
#get ⇒ Object
(also: #value)
Gets the current value.
-
#get_and_set(new_value) ⇒ Object
(also: #swap)
Atomically sets to the given value and returns the old value.
-
#set(new_value) ⇒ Object
(also: #value=)
Sets to the given value.
-
#swap(new_value)
Alias for #get_and_set.
- #synchronize private
AtomicNumericCompareAndSetWrapper
- Included
#compare_and_set | Atomically sets the value to the given updated value if the current value == the expected value. |
AtomicDirectUpdate
- Included
Constructor Details
.new(value = nil) ⇒ MutexAtomicReference
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 16
def initialize(value = nil) super() @Lock = ::Mutex.new @value = value end
Instance Attribute Details
#value (rw)
Alias for #get.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 26
alias_method :value, :get
#value=(new_value) (rw)
Alias for #set.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 32
alias_method :value=, :set
Instance Method Details
#_compare_and_set(old_value, new_value) ⇒ Boolean
Atomically sets the value to the given updated value if the current value == the expected value.
that the actual value was not equal to the expected value.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 45
def _compare_and_set(old_value, new_value) synchronize do if @value.equal? old_value @value = new_value true else false end end end
#compare_and_swap
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 13
alias_method :compare_and_swap, :compare_and_set
#get ⇒ Object Also known as: #value
Gets the current value.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 23
def get synchronize { @value } end
#get_and_set(new_value) ⇒ Object Also known as: #swap
Atomically sets to the given value and returns the old value.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 35
def get_and_set(new_value) synchronize do old_value = @value @value = new_value old_value end end
#set(new_value) ⇒ Object Also known as: #value=
Sets to the given value.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 29
def set(new_value) synchronize { @value = new_value } end
#swap(new_value)
Alias for #get_and_set.
# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 42
alias_method :swap, :get_and_set
#synchronize (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb', line 59
def synchronize if @Lock.owned? yield else @Lock.synchronize { yield } end end