Sha256: efa8df5287a9ef5fc255cebd27da88ea6e68042677f0086a881dc22bc5cd933e

Contents?: true

Size: 844 Bytes

Versions: 34

Compression:

Stored size: 844 Bytes

Contents

# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://home.gna.org/xmpp4r/

module Jabber
  ##
  # This class implements semaphore for threads synchronization.
  class Semaphore

    ##
    # Initialize new semaphore
    #
    # val:: [Integer] number of threads, that can enter to section
    def initialize(val=0)
      @tickets = val
      @lock = Mutex.new
      @cond = ConditionVariable.new
    end

    ##
    # Waits until are available some free tickets
    def wait
      @lock.synchronize {
        @cond.wait(@lock) while !(@tickets > 0)
        @tickets -= 1
      }
    end

    ##
    # Unlocks guarded section, increments number of free tickets
    def run
      @lock.synchronize {
        @tickets += 1
        @cond.signal
      }
    end
  end
end

Version data entries

34 entries across 34 versions & 13 rubygems

Version Path
brontes3d-xmpp4r-0.4 lib/xmpp4r/semaphore.rb
bryanl-xmpp4r-0.3.2 lib/xmpp4r/semaphore.rb
edavey-xmpp4r-0.4.1 lib/xmpp4r/semaphore.rb
edavey-xmpp4r-0.4.2 lib/xmpp4r/semaphore.rb
edavey-xmpp4r-0.4 lib/xmpp4r/semaphore.rb
heipei-xmpp4r-0.3.2 lib/xmpp4r/semaphore.rb
ln-xmpp4r-0.5 lib/xmpp4r/semaphore.rb
mojodna-xmpp4r-0.4.0.2 lib/xmpp4r/semaphore.rb
mojodna-xmpp4r-0.4.0.3 lib/xmpp4r/semaphore.rb
seanohalpin-xmpp4r-0.4.1 lib/xmpp4r/semaphore.rb
xmpp4r-0.5.5 lib/xmpp4r/semaphore.rb
gmcmillan-xmpp4r-0.6.2 lib/xmpp4r/semaphore.rb
gmcmillan-xmpp4r-0.6.1 lib/xmpp4r/semaphore.rb
gmcmillan-xmpp4r-0.6 lib/xmpp4r/semaphore.rb
gmcmillan-xmpp4r-0.5 lib/xmpp4r/semaphore.rb
mad-p-xmpp4r-0.6.3 lib/xmpp4r/semaphore.rb
mad-p-xmpp4r-0.6.2 lib/xmpp4r/semaphore.rb
mad-p-xmpp4r-0.6.1 lib/xmpp4r/semaphore.rb
mad-p-xmpp4r-0.6.0 lib/xmpp4r/semaphore.rb
cerberus-0.8.0 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb