Module: LightIO::Module::Thread::ClassMethods
Instance Method Summary collapse
- #current ⇒ Object
- #exclusive(&blk) ⇒ Object
- #finalizer(object_id) ⇒ Object
- #fork(*args, &blk) ⇒ Object (also: #start)
- #kill(thr) ⇒ Object
- #list ⇒ Object
- #main ⇒ Object
- #new(*args, &blk) ⇒ Object
- #pass ⇒ Object (also: #stop)
Instance Method Details
#current ⇒ Object
32 33 34 35 |
# File 'lib/lightio/module/thread.rb', line 32 def current return main if LightIO::Core::LightFiber.is_root?(Fiber.current) LightIO::Library::Thread.instance_variable_get(:@current_thread) || origin_current end |
#exclusive(&blk) ⇒ Object
37 38 39 |
# File 'lib/lightio/module/thread.rb', line 37 def exclusive(&blk) LightIO::Library::Thread.__send__(:thread_mutex).synchronize(&blk) end |
#finalizer(object_id) ⇒ Object
67 68 69 |
# File 'lib/lightio/module/thread.rb', line 67 def finalizer(object_id) proc {LightIO::Library::Thread.__send__(:threads).delete(object_id)} end |
#fork(*args, &blk) ⇒ Object Also known as: start
20 21 22 23 24 |
# File 'lib/lightio/module/thread.rb', line 20 def fork(*args, &blk) obj = LightIO::Library::Thread.__send__ :allocate obj.send(:init_core, *args, &blk) obj end |
#kill(thr) ⇒ Object
28 29 30 |
# File 'lib/lightio/module/thread.rb', line 28 def kill(thr) thr.kill end |
#list ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lightio/module/thread.rb', line 41 def list thread_list = [] LightIO::Library::Thread.__send__(:threads).keys.each {|id| begin thr = ObjectSpace._id2ref(id) unless thr.alive? # manually remove thr from threads thr.kill next end thread_list << thr rescue RangeError # mean object is recycled # just wait ruby GC call finalizer to remove it from threads next end } thread_list end |
#main ⇒ Object
71 72 73 |
# File 'lib/lightio/module/thread.rb', line 71 def main origin_main end |