From 31a93152c8977f31045bd182ae99df4ebd088abf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 5 Jan 2011 17:18:05 -0800 Subject: minor cleanups following state cleanups We noticed a few more things that could be cleaned up after the last commit. --- lib/rainbows.rb | 4 ++++ lib/rainbows/fiber_pool.rb | 2 +- lib/rainbows/fiber_spawn.rb | 2 +- lib/rainbows/thread_spawn.rb | 9 +++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/rainbows.rb b/lib/rainbows.rb index ae77dbe..76cb728 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -91,6 +91,10 @@ module Rainbows @alive && @server.master_pid == Process.ppid or quit! end + def self.cur_alive + @alive || @cur > 0 + end + def self.quit! @alive = false Rainbows::HttpParser.quit diff --git a/lib/rainbows/fiber_pool.rb b/lib/rainbows/fiber_pool.rb index 229f560..7e50723 100644 --- a/lib/rainbows/fiber_pool.rb +++ b/lib/rainbows/fiber_pool.rb @@ -34,6 +34,6 @@ module Rainbows::FiberPool end rescue => e Rainbows::Error.listen_loop(e) - end while Rainbows.alive || Rainbows.cur > 0 + end while Rainbows.cur_alive end end diff --git a/lib/rainbows/fiber_spawn.rb b/lib/rainbows/fiber_spawn.rb index 84df30d..b8552d7 100644 --- a/lib/rainbows/fiber_spawn.rb +++ b/lib/rainbows/fiber_spawn.rb @@ -23,6 +23,6 @@ module Rainbows::FiberSpawn end rescue => e Rainbows::Error.listen_loop(e) - end while Rainbows.alive || Rainbows.cur > 0 + end while Rainbows.cur_alive end end diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb index a0520d1..281e223 100644 --- a/lib/rainbows/thread_spawn.rb +++ b/lib/rainbows/thread_spawn.rb @@ -22,18 +22,19 @@ module Rainbows::ThreadSpawn def accept_loop(klass) #:nodoc: lock = Mutex.new limit = worker_connections + nr = 0 LISTENERS.each do |l| klass.new(l) do |l| begin - if lock.synchronize { Rainbows.cur >= limit } + if lock.synchronize { nr >= limit } worker_yield elsif c = l.kgio_accept klass.new(c) do |c| begin - lock.synchronize { Rainbows.cur += 1 } + lock.synchronize { nr += 1 } c.process_loop ensure - lock.synchronize { Rainbows.cur -= 1 } + lock.synchronize { nr -= 1 } end end end @@ -42,7 +43,7 @@ module Rainbows::ThreadSpawn end while Rainbows.alive end end - sleep 1 while Rainbows.tick || lock.synchronize { Rainbows.cur > 0 } + sleep 1 while Rainbows.tick || lock.synchronize { nr > 0 } end def worker_loop(worker) #:nodoc: -- cgit v1.2.3-24-ge0c7