Module: LightIO::Module::Thread::ClassMethods

Extended by:
Forwardable
Included in:
Library::Thread
Defined in:
lib/lightio/module/thread.rb

Instance Method Summary collapse

Instance Method Details

#currentObject



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

#listObject



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

#mainObject



71
72
73
# File 'lib/lightio/module/thread.rb', line 71

def main
  origin_main
end

#new(*args, &blk) ⇒ Object



14
15
16
17
18
# File 'lib/lightio/module/thread.rb', line 14

def new(*args, &blk)
  obj = LightIO::Library::Thread.__send__ :allocate
  obj.__send__ :initialize, *args, &blk
  obj
end

#passObject Also known as: stop



61
62
63
# File 'lib/lightio/module/thread.rb', line 61

def pass
  LightIO::Beam.pass
end