summaryrefslogtreecommitdiffstats
path: root/lib/evendoors/twirl.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-03 22:27:16 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-03 22:27:16 +0200
commit2ee48c4f18470e733f244c659221e243ff998416 (patch)
tree62949886912b3dc5eb9e000b211e7f45f17ed978 /lib/evendoors/twirl.rb
downloadedoors-ruby-2ee48c4f18470e733f244c659221e243ff998416.zip
edoors-ruby-2ee48c4f18470e733f244c659221e243ff998416.tar.gz
initial commit
Diffstat (limited to 'lib/evendoors/twirl.rb')
-rw-r--r--lib/evendoors/twirl.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/evendoors/twirl.rb b/lib/evendoors/twirl.rb
new file mode 100644
index 0000000..30ef169
--- /dev/null
+++ b/lib/evendoors/twirl.rb
@@ -0,0 +1,59 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+
+#
+module EvenDoors
+ #
+ class Twirl
+ #
+ @debug = false
+ @pool = {} # per particle class free list
+ @sys_fifo = [] # system particles fifo list
+ @app_fifo = [] # application particles fifo list
+ #
+ #
+ class << self
+ #
+ attr_accessor :debug
+ #
+ def release_p p
+ ( @pool[p.class] ||= [] ) << p
+ end
+ #
+ def require_p p_kls
+ l = @pool[p_kls]
+ return p_kls.new if l.nil?
+ p = l.pop
+ return p_kls.new if p.nil?
+ p.reset!
+ p
+ end
+ #
+ def send_p p
+ @app_fifo << p
+ end
+ #
+ def send_sys_p p
+ @sys_fifo << p
+ end
+ #
+ def twirl!
+ while @sys_fifo.length>0 or @app_fifo.length>0
+ while @sys_fifo.length>0
+ p = @sys_fifo.shift
+ p.door.process_sys p
+ end
+ while @app_fifo.length>0
+ p = @app_fifo.shift
+ p.door.process p
+ end
+ end
+ end
+ #
+ end
+ #
+ end
+ #
+end
+#
+# EOF