Sha256: 4633bcffed271fb4d3e1560ff339f0b391d580268a9e1c18ed9315187af5b467

Contents?: true

Size: 929 Bytes

Versions: 17

Compression:

Stored size: 929 Bytes

Contents

require 'thread'
require 'monitor'

module Dalli

  # Make Dalli threadsafe by using a lock around all
  # public server methods.
  #
  # Dalli::Server.extend(Dalli::Threadsafe)
  #
  module Threadsafe
    def self.extended(obj)
      obj.init_threadsafe
    end

    def request(op, *args)
      @lock.synchronize do
        super
      end
    end

    def alive?
      @lock.synchronize do
        super
      end
    end

    def close
      @lock.synchronize do
        super
      end
    end

    def multi_response_start
      @lock.synchronize do
        super
      end
    end

    def multi_response_nonblock
      @lock.synchronize do
        super
      end
    end

    def multi_response_abort
      @lock.synchronize do
        super
      end
    end

    def lock!
      @lock.mon_enter
    end

    def unlock!
      @lock.mon_exit
    end

    def init_threadsafe
      @lock = Monitor.new
    end
  end
end

Version data entries

17 entries across 15 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/dalli-2.7.6/lib/dalli/options.rb
tdiary-5.0.5 vendor/bundle/gems/dalli-2.7.6/lib/dalli/options.rb
tdiary-5.0.4 vendor/bundle/gems/dalli-2.7.6/lib/dalli/options.rb
dalli-2.7.6 lib/dalli/options.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/dalli-2.7.5/lib/dalli/options.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/dalli-2.7.5/lib/dalli/options.rb
dalli-2.7.5 lib/dalli/options.rb
dalli-2.7.4 lib/dalli/options.rb
dalli-2.7.3 lib/dalli/options.rb
dalli-2.7.2 lib/dalli/options.rb
dalli-2.7.1 lib/dalli/options.rb
dalli-2.7.0 lib/dalli/options.rb
dalli-2.6.4 lib/dalli/options.rb
dalli-2.6.3 lib/dalli/options.rb
dalli-2.6.2 lib/dalli/options.rb
dalli-2.6.1 lib/dalli/options.rb
dalli-2.6.0 lib/dalli/options.rb