Module: CRuby::Coroutine
- Defined in:
- lib/cruby/coroutine.rb
Constant Summary collapse
- @@rdyQ =
CRuby::Queue.new
- @@flag =
割り込み可能フラグ
false
- @@mutex =
Mutex.new
- @@condv =
ConditionVariable.new
Class Method Summary collapse
- .dispatch ⇒ Object
- .empty? ⇒ Boolean
- .enqueue(k) ⇒ Object
-
.interrupt ⇒ Object
メインスレッドに割り込みをかける.
-
.interruptible(flag) ⇒ Object
割り込み可能フラグをセットする.
- .rdyq ⇒ Object
- .spawn(&f) ⇒ Object
Class Method Details
.dispatch ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/cruby/coroutine.rb', line 65 def self.dispatch k = @@rdyQ.dequeue if k != nil then k.call assert false end IOT.exec end |
.empty? ⇒ Boolean
61 62 63 |
# File 'lib/cruby/coroutine.rb', line 61 def self.empty? @@rdyQ.empty? end |
.enqueue(k) ⇒ Object
82 83 84 |
# File 'lib/cruby/coroutine.rb', line 82 def self.enqueue k @@rdyQ.enqueue(k) end |
.interrupt ⇒ Object
メインスレッドに割り込みをかける
42 43 44 45 46 47 48 49 |
# File 'lib/cruby/coroutine.rb', line 42 def self.interrupt # 割り込み可能になるまで待つ @@mutex.synchronize { while not @@flag @@condv.wait(@@mutex) end } end |
.interruptible(flag) ⇒ Object
割り込み可能フラグをセットする
52 53 54 55 56 57 58 59 |
# File 'lib/cruby/coroutine.rb', line 52 def self.interruptible flag @@mutex.synchronize { if flag @@condv.signal end @@flag = flag } end |
.rdyq ⇒ Object
37 38 39 |
# File 'lib/cruby/coroutine.rb', line 37 def self.rdyq p @@rdyQ end |