Sha256: 335c06e61006eff10a2a42845bca810c5752afdbc2f52668d117c4e9f05deeb6

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 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

      protected

      def synchronize(&block)
        if @__owner__ == Thread.current
          yield
        else
          Rubinius.lock(self)
          begin
            @__owner__ = Thread.current
            result = yield
          ensure
            @__owner__ = nil
            Rubinius.unlock(self)
            result
          end
        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

6 entries across 6 versions & 1 rubygems

Version Path
concurrent-ruby-1.0.0.pre4-java lib/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.0.0.pre4 lib/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.0.0.pre3-java lib/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.0.0.pre3 lib/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.0.0.pre2-java lib/concurrent/synchronization/rbx_lockable_object.rb
concurrent-ruby-1.0.0.pre2 lib/concurrent/synchronization/rbx_lockable_object.rb