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
cerberus-0.7.9 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
edavis10-cerberus-0.7.8 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7.8 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7.7 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7.6 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7.2 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7.5 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
cerberus-0.7 lib/vendor/xmpp4r/lib/xmpp4r/semaphore.rb
xmpp4r-0.5 lib/xmpp4r/semaphore.rb
mack-notifier-0.8.3 lib/gems/xmpp4r-0.4/lib/xmpp4r/semaphore.rb
mack-notifier-0.8.3.1 lib/gems/xmpp4r-0.4/lib/xmpp4r/semaphore.rb
mack-notifier-0.8.2 lib/gems/xmpp4r-0.4/lib/xmpp4r/semaphore.rb
xmpp4r-0.3.2 lib/xmpp4r/semaphore.rb
xmpp4r-0.4 lib/xmpp4r/semaphore.rb