Class: Higgs::CountDownLatch

Inherits:
Object
  • Object
show all
Defined in:
lib/higgs/thread.rb

Constant Summary collapse

CVS_ID =

for ident(1)

'$Id: thread.rb 841 2008-12-24 09:23:20Z toki $'

Instance Method Summary collapse

Constructor Details

#initialize(count) ⇒ CountDownLatch

Returns a new instance of CountDownLatch.



138
139
140
141
142
# File 'lib/higgs/thread.rb', line 138

def initialize(count)
  @count = count
  @lock = Mutex.new
  @cond = ConditionVariable.new
end

Instance Method Details

#count_downObject



144
145
146
147
148
149
150
151
152
# File 'lib/higgs/thread.rb', line 144

def count_down
  @lock.synchronize{
    if (@count > 0) then
      @count -= 1
      @cond.broadcast if (@count == 0)
    end
  }
  nil
end

#waitObject



154
155
156
157
158
159
160
161
# File 'lib/higgs/thread.rb', line 154

def wait
  @lock.synchronize{
    while (@count > 0)
      @cond.wait(@lock)
    end
  }
  nil
end