summaryrefslogtreecommitdiff
path: root/lib/webrick/utils.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-05 06:09:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-05 06:09:17 +0000
commit8d66627161fab5cc65dfb702e3285eb4fef221e8 (patch)
treecc872fd6ae0ab0fa471a293a9dfb7706d226f883 /lib/webrick/utils.rb
parentb01c28eeb3942bce1ddf9b9243ecf727d5421c6d (diff)
leakchecker.rb: remove temporary measure
* lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#watcher): make watcher thread restartable. * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#terminate): new method to terminate watcher thread. * test/lib/leakchecker.rb (LeakChecker#find_threads): revert r46941. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/utils.rb')
-rw-r--r--lib/webrick/utils.rb38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index 9c978a2b7b..846829b01f 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -124,8 +124,6 @@ module WEBrick
class TimeoutHandler
include Singleton
- class Thread < ::Thread; end
-
##
# Mutex used to synchronize access across threads
TimeoutMutex = Mutex.new # :nodoc:
@@ -145,6 +143,10 @@ module WEBrick
instance.cancel(Thread.current, id)
end
+ def self.terminate
+ instance.terminate
+ end
+
##
# Creates a new TimeoutHandler. You should use ::register and ::cancel
# instead of creating the timeout handler directly.
@@ -153,7 +155,12 @@ module WEBrick
@timeout_info = Hash.new
}
@queue = Queue.new
- @watcher = Thread.start{
+ @watcher = nil
+ end
+
+ # :nodoc:
+ private \
+ def watch
to_interrupt = []
while true
now = Time.now
@@ -184,8 +191,17 @@ module WEBrick
end
@queue.clear
end
- }
- end
+ end
+
+ # :nodoc:
+ private \
+ def watcher
+ (w = @watcher)&.alive? and return w # usual case
+ TimeoutMutex.synchronize{
+ (w = @watcher)&.alive? and next w # pathological check
+ @watcher = Thread.start(&method(:watch))
+ }
+ end
##
# Interrupts the timeout handler +id+ and raises +exception+
@@ -203,10 +219,10 @@ module WEBrick
def register(thread, time, exception)
info = nil
TimeoutMutex.synchronize{
- @timeout_info[thread] ||= Array.new
- @timeout_info[thread] << (info = [time, exception])
+ (@timeout_info[thread] ||= []) << (info = [time, exception])
}
@queue.push nil
+ watcher
return info.object_id
end
@@ -224,6 +240,14 @@ module WEBrick
return false
}
end
+
+ ##
+ def terminate
+ TimeoutMutex.synchronize{
+ @timeout_info.clear
+ @watcher&.kill&.join
+ }
+ end
end
##