Class: Agent::WaitGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/wait_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWaitGroup

Returns a new instance of WaitGroup.



7
8
9
10
11
# File 'lib/agent/wait_group.rb', line 7

def initialize
  @count = 0
  @mutex = Mutex.new
  @cvar  = ConditionVariable.new
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/agent/wait_group.rb', line 5

def count
  @count
end

Instance Method Details

#add(delta) ⇒ Object



21
22
23
24
25
# File 'lib/agent/wait_group.rb', line 21

def add(delta)
  @mutex.synchronize do
    modify_count(delta)
  end
end

#doneObject



27
28
29
30
31
# File 'lib/agent/wait_group.rb', line 27

def done
  @mutex.synchronize do
    modify_count(-1)
  end
end

#waitObject



13
14
15
16
17
18
19
# File 'lib/agent/wait_group.rb', line 13

def wait
  @mutex.synchronize do
    while @count > 0
      @cvar.wait(@mutex)
    end
  end
end