Sha256: 71de5c3b11c9713df73fd414fc979fc1c68b44199202baebfa667642c54abc1c
Contents?: true
Size: 840 Bytes
Versions: 1
Compression:
Stored size: 840 Bytes
Contents
# =XMPP4R - XMPP Library for Ruby # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option. # Website::http://xmpp4r.github.io 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xmpp4r-0.5.6 | lib/xmpp4r/semaphore.rb |