Sha256: acd8a8ab54a4d0b40466799cf0372c85a36aadabd34762759d98b84f11f37532

Contents?: true

Size: 1.55 KB

Versions: 23

Compression:

Stored size: 1.55 KB

Contents

module Concurrent
  module Synchronization

    # @!visibility private
    # @!macro internal_implementation_note
    class RbxLockableObject < AbstractLockableObject
      safe_initialization!

      def initialize(*defaults)
        super(*defaults)
        @__Waiters__ = []
        @__owner__   = nil
      end

      def initialize_copy(other)
        super
        @__Waiters__ = []
        @__owner__   = nil
      end

      protected

      def synchronize(&block)
        if @__owner__ == Thread.current
          yield
        else
          result = nil
          Rubinius.synchronize(self) do
            begin
              @__owner__ = Thread.current
              result     = yield
            ensure
              @__owner__ = nil
            end
          end
          result
        end
      end

      def ns_wait(timeout = nil)
        wchan = Rubinius::Channel.new

        begin
          @__Waiters__.push wchan
          Rubinius.unlock(self)
          signaled = wchan.receive_timeout timeout
        ensure
          Rubinius.lock(self)

          if !signaled && !@__Waiters__.delete(wchan)
            # we timed out, but got signaled afterwards,
            # so pass that signal on to the next waiter
            @__Waiters__.shift << true unless @__Waiters__.empty?
          end
        end

        self
      end

      def ns_signal
        @__Waiters__.shift << true unless @__Waiters__.empty?
        self
      end

      def ns_broadcast
        @__Waiters__.shift << true until @__Waiters__.empty?
        self
      end
    end
  end
end

Version data entries

23 entries across 21 versions & 10 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
o-concurrent-ruby-1.1.13 lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
o-concurrent-ruby-1.1.12 lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
o-concurrent-ruby-1.1.11 lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.1.10 lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb