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
This commit is contained in:
parent
5227d61ebf
commit
8f6fed850a
@ -1,4 +1,7 @@
|
|||||||
Tue Jul 14 11:20:13 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Jul 14 11:21:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#initialize):
|
||||||
|
make sleep intervals adaptive than fixed period intervals.
|
||||||
|
|
||||||
* lib/webrick/server.rb (WEBrick::GenericServer#start): flush
|
* lib/webrick/server.rb (WEBrick::GenericServer#start): flush
|
||||||
shutdown pipe.
|
shutdown pipe.
|
||||||
|
@ -156,15 +156,23 @@ module WEBrick
|
|||||||
Thread.start{
|
Thread.start{
|
||||||
while true
|
while true
|
||||||
now = Time.now
|
now = Time.now
|
||||||
@timeout_info.keys.each{|thread|
|
wakeup = nil
|
||||||
ary = @timeout_info[thread]
|
@timeout_info.each {|thread, ary|
|
||||||
next unless ary
|
next unless ary
|
||||||
ary.dup.each{|info|
|
ary.dup.each{|info|
|
||||||
time, exception = *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
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user