Sha256: da1ac3c54d31089265d9b6b0ba738163bf948082ae6379fca34e521e548b6b03

Contents?: true

Size: 1.07 KB

Versions: 113

Compression:

Stored size: 1.07 KB

Contents

require "set"
require "thread"

module Bunny
  module Concurrent
    # A SortedSet variation that synchronizes key mutation operations.
    #
    # @note This is NOT a complete SortedSet replacement. It only synchronizes operations needed by Bunny.
    # @api public
    class SynchronizedSortedSet < SortedSet
      def initialize(enum = nil)
        @mutex = Mutex.new

        super
      end

      def add(o)
        # avoid using Mutex#synchronize because of a Ruby 1.8.7-specific
        # bug that prevents super from being called from within a block. MK.
        @mutex.lock
        begin
          super
        ensure
          @mutex.unlock
        end
      end

      def delete(o)
        @mutex.lock
        begin
          super
        ensure
          @mutex.unlock
        end
      end

      def delete_if(&block)
        @mutex.lock
        begin
          super
        ensure
          @mutex.unlock
        end
      end

      def include?(o)
        @mutex.lock
        begin
          super
        ensure
          @mutex.unlock
        end
      end
    end
  end
end

Version data entries

113 entries across 113 versions & 2 rubygems

Version Path
bunny-1.6.1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.6.0 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.5.1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.6.0.rc2 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.6.0.rc1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.6.0.pre1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.5.0 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.5.0.pre2 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.5.0.pre1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.4.1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.4.0 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.3.1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.3.0 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.2.2 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.2.1 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.2.0 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.1.9 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.1.8 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.1.7 lib/bunny/concurrent/synchronized_sorted_set.rb
bunny-1.1.6 lib/bunny/concurrent/synchronized_sorted_set.rb