Maintain a thread pool FOR SPEED!!
# File lib/celluloid/internal_pool.rb, line 47 def active? busy_size + idle_size > 0 end
# File lib/celluloid/internal_pool.rb, line 32 def assert_inactive if active? message = "Thread pool is still active" if defined?(JRUBY_VERSION) Celluloid.logger.warn message else raise Error, message end end end
# File lib/celluloid/internal_pool.rb, line 28 def assert_running raise Error, "Thread pool is not running" unless running? end
# File lib/celluloid/internal_pool.rb, line 20 def busy_size @busy_size end
# File lib/celluloid/internal_pool.rb, line 51 def each to_a.each {|thread| yield thread } end
Get a thread from the pool, running the given block
# File lib/celluloid/internal_pool.rb, line 60 def get(&block) @mutex.synchronize do assert_running begin if @idle_threads.empty? thread = create else thread = @idle_threads.pop @idle_size = @idle_threads.length end end until thread.status # handle crashed threads thread.busy = true @busy_size += 1 thread[:celluloid_queue] << block thread end end
# File lib/celluloid/internal_pool.rb, line 24 def idle_size @idle_size end
# File lib/celluloid/internal_pool.rb, line 110 def kill @mutex.synchronize do finalize @running = false @all_threads.shift.kill until @all_threads.empty? @idle_threads.clear @busy_size = 0 @idle_size = 0 end end
Return a thread to the pool
# File lib/celluloid/internal_pool.rb, line 81 def put(thread) @mutex.synchronize do thread.busy = false if idle_size + 1 >= @max_idle thread[:celluloid_queue] << nil @busy_size -= 1 @all_threads.delete(thread) else @idle_threads.push thread @busy_size -= 1 @idle_size = @idle_threads.length clean_thread_locals(thread) end end end
# File lib/celluloid/internal_pool.rb, line 43 def running? @running end
Generated with the Darkfish Rdoc Generator 2.