Sha256: 767eedc8437d3f55eae701c444cfdd103e96d81ffb5eb588ad14c9f108fdf920

Contents?: true

Size: 1.55 KB

Versions: 163

Compression:

Stored size: 1.55 KB

Contents

require 'concurrent/synchronization'
require 'concurrent/utility/native_integer'

module Concurrent

  # @!macro atomic_fixnum
  # @!visibility private
  # @!macro internal_implementation_note
  class MutexAtomicFixnum < Synchronization::LockableObject

    # @!macro atomic_fixnum_method_initialize
    def initialize(initial = 0)
      super()
      synchronize { ns_initialize(initial) }
    end

    # @!macro atomic_fixnum_method_value_get
    def value
      synchronize { @value }
    end

    # @!macro atomic_fixnum_method_value_set
    def value=(value)
      synchronize { ns_set(value) }
    end

    # @!macro atomic_fixnum_method_increment
    def increment(delta = 1)
      synchronize { ns_set(@value + delta.to_i) }
    end

    alias_method :up, :increment

    # @!macro atomic_fixnum_method_decrement
    def decrement(delta = 1)
      synchronize { ns_set(@value - delta.to_i) }
    end

    alias_method :down, :decrement

    # @!macro atomic_fixnum_method_compare_and_set
    def compare_and_set(expect, update)
      synchronize do
        if @value == expect.to_i
          @value = update.to_i
          true
        else
          false
        end
      end
    end

    # @!macro atomic_fixnum_method_update
    def update
      synchronize do
        @value = yield @value
      end
    end

    protected

    # @!visibility private
    def ns_initialize(initial)
      ns_set(initial)
    end

    private

    # @!visibility private
    def ns_set(value)
      Utility::NativeInteger.ensure_integer_and_bounds value
      @value = value
    end
  end
end

Version data entries

163 entries across 145 versions & 34 rubygems

Version Path
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
concurrent-ruby-1.1.9 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
concurrent-ruby-1.1.8 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
concurrent-ruby-1.1.7 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb