Sha256: d9af882277bc9ac9a21025baa5d601a674ae0430723ed55cff4f5326386f2850

Contents?: true

Size: 845 Bytes

Versions: 103

Compression:

Stored size: 845 Bytes

Contents

require 'concurrent/errors'

module Concurrent

  # Define update methods that use direct paths
  #
  # @!visibility private
  # @!macro internal_implementation_note
  module AtomicDirectUpdate
    def update
      true until compare_and_set(old_value = get, new_value = yield(old_value))
      new_value
    end

    def try_update
      old_value = get
      new_value = yield old_value

      return unless compare_and_set old_value, new_value

      new_value
    end

    def try_update!
      old_value = get
      new_value = yield old_value
      unless compare_and_set(old_value, new_value)
        if $VERBOSE
          raise ConcurrentUpdateError, "Update failed"
        else
          raise ConcurrentUpdateError, "Update failed", ConcurrentUpdateError::CONC_UP_ERR_BACKTRACE
        end
      end
      new_value
    end
  end
end

Version data entries

103 entries across 103 versions & 16 rubygems

Version Path
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic_reference/atomic_direct_update.rb