Sha256: d81767b05bdd99e8126628dc894de608e899cb828c3aa4781418088e2102308a

Contents?: true

Size: 1.35 KB

Versions: 103

Compression:

Stored size: 1.35 KB

Contents

require 'concurrent/synchronization/safe_initialization'

module Concurrent

  # @!macro atomic_boolean
  # @!visibility private
  # @!macro internal_implementation_note
  class MutexAtomicBoolean
    extend Concurrent::Synchronization::SafeInitialization

    # @!macro atomic_boolean_method_initialize
    def initialize(initial = false)
      super()
      @Lock = ::Mutex.new
      @value = !!initial
    end

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

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

    # @!macro atomic_boolean_method_true_question
    def true?
      synchronize { @value }
    end

    # @!macro atomic_boolean_method_false_question
    def false?
      synchronize { !@value }
    end

    # @!macro atomic_boolean_method_make_true
    def make_true
      synchronize { ns_make_value(true) }
    end

    # @!macro atomic_boolean_method_make_false
    def make_false
      synchronize { ns_make_value(false) }
    end

    protected

    # @!visibility private
    def synchronize
      if @Lock.owned?
        yield
      else
        @Lock.synchronize { yield }
      end
    end

    private

    # @!visibility private
    def ns_make_value(value)
      old = @value
      @value = value
      old != @value
    end
  end
end

Version data entries

103 entries across 103 versions & 16 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.4/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.3.4 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.3/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.3.3 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.3.2 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/concurrent-ruby-1.3.1/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.3.1 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.3.1.pre lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
concurrent-ruby-1.2.3 lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb