Class: VR::Thread
- Inherits:
-
Object
- Object
- VR::Thread
- Defined in:
- lib/Thread.rb
Class Method Summary collapse
- .destroy ⇒ Object
- .flush ⇒ Object
- .init ⇒ Object
- .new(*args, &block) ⇒ Object
- .protect(&block) ⇒ Object
- .protect_call(obj, sym, *args) ⇒ Object
Class Method Details
.destroy ⇒ Object
22 23 24 |
# File 'lib/Thread.rb', line 22 def self.destroy @@running = false end |
.flush ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/Thread.rb', line 48 def self.flush if @@mutex.try_lock @@pending_calls.each do |closuer| closuer.call end @@pending_calls = [] @@mutex.unlock end end |
.init ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/Thread.rb', line 7 def self.init @@mutex = Mutex.new @@pending_calls = [] @@running = true GLib::Timeout.add(100) do @@mutex.synchronize do @@pending_calls.each do |closuer| closuer.call end @@pending_calls = [] end @@running end end |
.new(*args, &block) ⇒ Object
3 4 5 |
# File 'lib/Thread.rb', line 3 def self.new(*args,&block) ::Thread.new(*args,&block) end |
.protect(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/Thread.rb', line 26 def self.protect(&block) if ::Thread.current == ::Thread.main block.call else @@mutex.synchronize do @@pending_calls << block end end end |
.protect_call(obj, sym, *args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/Thread.rb', line 36 def self.protect_call(obj,sym,*args) if ::Thread.current == ::Thread.main obj.__send__(sym,*args) else @@mutex.synchronize do @@pending_calls << Proc.new do obj.__send__(sym,*args) end end end end |