Class: ServerEngine::SignalThread
- Inherits:
-
Thread
- Object
- Thread
- ServerEngine::SignalThread
- Defined in:
- lib/serverengine/signal_thread.rb
Instance Method Summary collapse
- #handlers ⇒ Object
-
#initialize(&block) ⇒ SignalThread
constructor
A new instance of SignalThread.
- #stop ⇒ Object
- #trap(sig, command = nil, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ SignalThread
Returns a new instance of SignalThread.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/serverengine/signal_thread.rb', line 21 def initialize(&block) @handlers = {} @mutex = Mutex.new @cond = ConditionVariable.new @queue = [] @finished = false block.call(self) if block super(&method(:main)) end |
Instance Method Details
#handlers ⇒ Object
54 55 56 |
# File 'lib/serverengine/signal_thread.rb', line 54 def handlers @handlers.dup end |
#stop ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/serverengine/signal_thread.rb', line 58 def stop @mutex.synchronize do @finished = true @cond.broadcast end self end |
#trap(sig, command = nil, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/serverengine/signal_thread.rb', line 34 def trap(sig, command=nil, &block) # normalize signal names sig = sig.to_s.upcase if sig[0,3] == "SIG" sig = sig[3..-1] end sig = sig.to_sym old = @handlers[sig] if block Kernel.trap(sig) { signal_handler_main(sig) } @handlers[sig] = block else Kernel.trap(sig, command) @handlers.delete(sig) end old end |