Class: Wakame::Rule::BasicActionSet::Lock

Inherits:
Object
  • Object
show all
Defined in:
lib/wakame/rule.rb

Direct Known Subclasses

MockLock

Instance Method Summary collapse

Constructor Details

#initializeLock

Returns a new instance of Lock.



12
13
14
15
# File 'lib/wakame/rule.rb', line 12

def initialize
  @mutex = Mutex.new
  @cond = ConditionVariable.new
end

Instance Method Details

#signalObject



17
18
19
20
21
# File 'lib/wakame/rule.rb', line 17

def signal
  @mutex.synchronize {
    @cond.signal
  }
end

#wait(&blk) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wakame/rule.rb', line 23

def wait(&blk)
  if blk.nil?
    i=0
    blk = proc {
      i += 1
      i > 1 ? true : false
    }
  end
  @mutex.synchronize {
    @cond.wait(@mutex) while blk.call
  }
end