diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-14 02:21:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-14 02:21:53 +0000 |
commit | 8f6fed850a08ffbc7aa9abb2a941faa6c47b3a18 (patch) | |
tree | b00df3adbfcaeb56af85574d501371d1e488ba2a /lib/webrick | |
parent | 5227d61ebf69d646a41d9ae14b9fd41d9d0b5438 (diff) | |
download | ruby-8f6fed850a08ffbc7aa9abb2a941faa6c47b3a18.tar.gz |
webrick/utils.rb: adaptive sleep
* lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#initialize):
make sleep intervals adaptive than fixed period intervals.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick')
-rw-r--r-- | lib/webrick/utils.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index bde3d01ca5..c6da8449df 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -156,15 +156,23 @@ module WEBrick Thread.start{ while true now = Time.now - @timeout_info.keys.each{|thread| - ary = @timeout_info[thread] + wakeup = nil + @timeout_info.each {|thread, ary| next unless ary ary.dup.each{|info| time, exception = *info - interrupt(thread, info.object_id, exception) if time < now + if time < now + interrupt(thread, info.object_id, exception) + elsif !wakeup || time < wakeup + wakeup = time + end } } - sleep 0.5 + if !wakeup + sleep + elsif (wakeup -= now) > 0 + sleep(wakeup) + end end } end |