Module: Yoshinon
- Defined in:
- lib/yoshinon.rb,
lib/yoshinon/deshite.rb,
lib/yoshinon/version.rb
Defined Under Namespace
Classes: Deshite
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
Class Method Details
.define_trap(signal) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yoshinon.rb', line 17 def self.define_trap(signal) Signal.trap(signal) do |value| @on_trap.each{|e| e.call(value)} Thread.new do @mutex.synchronize do @cv.wait(@mutex) until @deshite_set.empty? end exit 130 end end end |
.lock ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yoshinon.rb', line 29 def self.lock if block_given? deshite = lock begin yield ensure unlock(deshite) end else deshite = Deshite.new @mutex.synchronize do @deshite_set << deshite end deshite end end |
.on_trap(&block) ⇒ Object
13 14 15 |
# File 'lib/yoshinon.rb', line 13 def self.on_trap(&block) @on_trap << block end |
.unlock(deshite) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/yoshinon.rb', line 46 def self.unlock(deshite) @mutex.synchronize do @deshite_set.delete(deshite) @cv.broadcast end end |