about summary refs log tree commit homepage
path: root/lib/rainbows/thread_spawn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-27 02:43:44 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-27 02:43:44 +0000
commit94b848a8f9120bce8b0abd776b1a9b7e2f4fa30d (patch)
tree672d1f677360e849bb4bf5200dc87ec266f701dc /lib/rainbows/thread_spawn.rb
parenta310302708faa19042282e94525544cfbb23eba5 (diff)
downloadrainbows-94b848a8f9120bce8b0abd776b1a9b7e2f4fa30d.tar.gz
This lets Rainbows! yield the current worker process
when busy in the hopes another worker will pick up the
slack.  We can also override this for the single worker
process case later if people care enough.
Diffstat (limited to 'lib/rainbows/thread_spawn.rb')
-rw-r--r--lib/rainbows/thread_spawn.rb12
1 files changed, 2 insertions, 10 deletions
diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb
index a0ccde6..9da75f1 100644
--- a/lib/rainbows/thread_spawn.rb
+++ b/lib/rainbows/thread_spawn.rb
@@ -18,6 +18,7 @@ module Rainbows
 
   module ThreadSpawn
     include Base
+    include Rainbows::WorkerYield
 
     def accept_loop(klass) #:nodoc:
       lock = Mutex.new
@@ -26,16 +27,7 @@ module Rainbows
         klass.new(l) do |l|
           begin
             if lock.synchronize { G.cur >= limit }
-              # Sleep if we're busy, another less busy worker process may
-              # take it for us if we sleep. This is gross but other options
-              # still suck because they require expensive/complicated
-              # synchronization primitives for _every_ case, not just this
-              # unlikely one.  Since this case is (or should be) uncommon,
-              # just busy wait when we have to.
-              # We don't use Thread.pass because it needlessly spins the
-              # CPU during I/O wait, CPU cycles that can be better used
-              # by other worker _processes_.
-              sleep(0.01)
+              worker_yield
             elsif c = l.kgio_accept
               klass.new(c) do |c|
                 begin