Class: Concurrent::AtomicFixnum
- Inherits:
-
Object
- Object
- Concurrent::AtomicFixnum
- Defined in:
- lib/concurrent/atomic.rb
Overview
A numeric value that can be updated atomically. Reads and writes to an atomic fixnum and thread-safe and guaranteed to succeed. Reads and writes may block briefly but no explicit locking is required.
Instance Method Summary collapse
-
#decrement ⇒ Fixnum
(also: #down)
Decreases the current value by 1.
-
#increment ⇒ Fixnum
(also: #up)
Increases the current value by 1.
-
#initialize(init = 0) ⇒ AtomicFixnum
constructor
Creates a new
AtomicFixnumwith the given initial value. -
#value ⇒ Fixnum
Retrieves the current
Fixnumvalue. -
#value=(value) ⇒ Fixnum
Explicitly sets the value.
Constructor Details
#initialize(init = 0) ⇒ AtomicFixnum
Creates a new AtomicFixnum with the given initial value.
111 112 113 114 |
# File 'lib/concurrent/atomic.rb', line 111 def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) allocate_storage(init) end |
Instance Method Details
#decrement ⇒ Fixnum Also known as: down
Decreases the current value by 1
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/concurrent/atomic.rb', line 105 class AtomicFixnum # Creates a new +AtomicFixnum+ with the given initial value. # # @param [Fixnum] init the initial value # @raise [ArgumentError] if the initial value is not a +Fixnum+ def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) allocate_storage(init) end if defined? java.util include JavaAtomicFixnum else include MutexAtomicFixnum end alias_method :up, :increment alias_method :down, :decrement end |
#increment ⇒ Fixnum Also known as: up
Increases the current value by 1
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/concurrent/atomic.rb', line 105 class AtomicFixnum # Creates a new +AtomicFixnum+ with the given initial value. # # @param [Fixnum] init the initial value # @raise [ArgumentError] if the initial value is not a +Fixnum+ def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) allocate_storage(init) end if defined? java.util include JavaAtomicFixnum else include MutexAtomicFixnum end alias_method :up, :increment alias_method :down, :decrement end |
#value ⇒ Fixnum
Retrieves the current Fixnum value
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/concurrent/atomic.rb', line 105 class AtomicFixnum # Creates a new +AtomicFixnum+ with the given initial value. # # @param [Fixnum] init the initial value # @raise [ArgumentError] if the initial value is not a +Fixnum+ def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) allocate_storage(init) end if defined? java.util include JavaAtomicFixnum else include MutexAtomicFixnum end alias_method :up, :increment alias_method :down, :decrement end |
#value=(value) ⇒ Fixnum
Explicitly sets the value
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/concurrent/atomic.rb', line 105 class AtomicFixnum # Creates a new +AtomicFixnum+ with the given initial value. # # @param [Fixnum] init the initial value # @raise [ArgumentError] if the initial value is not a +Fixnum+ def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) allocate_storage(init) end if defined? java.util include JavaAtomicFixnum else include MutexAtomicFixnum end alias_method :up, :increment alias_method :down, :decrement end |