Class: CRuby::Channel
- Inherits:
-
Object
- Object
- CRuby::Channel
- Defined in:
- lib/cruby/channel.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #recv ⇒ Object
-
#recvEvt ⇒ Object
受信イベントを生成する.
- #send(msg) ⇒ Object
-
#sendEvt(msg) ⇒ Object
送信イベントを生成する.
Constructor Details
Instance Method Details
#recv ⇒ Object
12 13 14 |
# File 'lib/cruby/channel.rb', line 12 def recv recvEvt.sync end |
#recvEvt ⇒ Object
受信イベントを生成する
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cruby/channel.rb', line 32 def recvEvt pollFn = Proc.new { @sendQ.poll } doFn = Proc.new { item = @sendQ.dequeue item['flg'][0] = true CRuby::Coroutine.enqueue(item['cont']) item['msg'] } blockFn = Proc.new {|flg,k| @recvQ.enqueue({'flg'=>flg,'cont'=>k}) } CRuby::Event.new([CRuby::Event::BEvt.new(pollFn, doFn, blockFn)]) end |
#send(msg) ⇒ Object
8 9 10 |
# File 'lib/cruby/channel.rb', line 8 def send msg sendEvt(msg).sync end |
#sendEvt(msg) ⇒ Object
送信イベントを生成する
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cruby/channel.rb', line 17 def sendEvt msg pollFn = Proc.new { @recvQ.poll } doFn = Proc.new { callcc {|k| item = @recvQ.dequeue item['flg'][0] = true CRuby::Coroutine.enqueue(k) item['cont'].call(msg) } } blockFn = Proc.new {|flg,k| @sendQ.enqueue({'flg'=>flg,'msg'=>msg,'cont'=>k}) } CRuby::Event.new([CRuby::Event::BEvt.new(pollFn, doFn, blockFn)]) end |