Class: ServerEngine::BlockingFlag

Inherits:
Object
  • Object
show all
Defined in:
lib/serverengine/blocking_flag.rb

Instance Method Summary collapse

Constructor Details

#initializeBlockingFlag

Returns a new instance of BlockingFlag.



22
23
24
25
26
# File 'lib/serverengine/blocking_flag.rb', line 22

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

Instance Method Details

#reset!Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/serverengine/blocking_flag.rb', line 40

def reset!
  toggled = false
  @mutex.synchronize do
    if @set
      @set = false
      toggled = true
    end
    @cond.broadcast
  end
  return toggled
end

#set!Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/serverengine/blocking_flag.rb', line 28

def set!
  toggled = false
  @mutex.synchronize do
    unless @set
      @set = true
      toggled = true
    end
    @cond.broadcast
  end
  return toggled
end

#set?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/serverengine/blocking_flag.rb', line 52

def set?
  @set
end

#wait_for_reset(timeout = nil) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/serverengine/blocking_flag.rb', line 67

def wait_for_reset(timeout=nil)
  @mutex.synchronize do
    if @set
      @cond.wait(@mutex, timeout)
    end
    return !@set
  end
end

#wait_for_set(timeout = nil) ⇒ Object Also known as: wait



56
57
58
59
60
61
62
63
# File 'lib/serverengine/blocking_flag.rb', line 56

def wait_for_set(timeout=nil)
  @mutex.synchronize do
    unless @set
      @cond.wait(@mutex, timeout)
    end
    return @set
  end
end