Sha256: 2cfd501e28cac9782e3555c408e09922546f6de396117ad2c3c5bcc3ad267d52

Contents?: true

Size: 627 Bytes

Versions: 260

Compression:

Stored size: 627 Bytes

Contents

module Listen
  # Allows two threads to wait on eachother.
  #
  # @note Only two threads can be used with this Turnstile
  #   because of the current implementation.
  class Turnstile

    # Initialize the turnstile.
    #
    def initialize
      # Until ruby offers semahpores, only queues can be used
      # to implement a turnstile.
      @q = Queue.new
    end

    # Blocks the current thread until a signal is received.
    #
    def wait
      @q.pop if @q.num_waiting == 0
    end

    # Unblocks the waiting thread if there is one.
    #
    def signal
      @q.push :dummy if @q.num_waiting == 1
    end
  end
end

Version data entries

260 entries across 165 versions & 10 rubygems

Version Path
sass-3.3.0.alpha.8 vendor/listen/lib/listen/turnstile.rb
sass-3.3.0.alpha.15 vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.6 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.6 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.6 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.5 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.5 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.5 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.4 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.4 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.4 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.3 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.3 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.3 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.2 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.2 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.2 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.1 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.1 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/turnstile.rb
classiccms-0.6.1 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/turnstile.rb