From 5024323bcfe81aa40fa0480c65aa876e8588987a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 24 Mar 2017 19:52:55 +0000 Subject: avoid Thread#[] and Thread#[]= across threads Support for it may be removed in future versions of Ruby(*), and we actually do not need to waste time looping when a instance variable will do. (*) https://bugs.ruby-lang.org/issues/13245 --- lib/yahns/acceptor.rb | 6 +++--- lib/yahns/server.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/yahns/acceptor.rb b/lib/yahns/acceptor.rb index 7ab9f60..7340a1a 100644 --- a/lib/yahns/acceptor.rb +++ b/lib/yahns/acceptor.rb @@ -24,7 +24,7 @@ module Yahns::Acceptor # :nodoc: close return true end - @thrs.each { |t| t[:yahns_quit] = true } + @quit = true return true if __ac_quit_done? @thrs.each do @@ -42,10 +42,10 @@ module Yahns::Acceptor # :nodoc: end def spawn_acceptor(nr, logger, client_class) + @quit = false @thrs = nr.times.map do Thread.new do queue = client_class.queue - t = Thread.current accept_flags = Kgio::SOCK_NONBLOCK | Kgio::SOCK_CLOEXEC qev_flags = client_class.superclass::QEV_FLAGS begin @@ -64,7 +64,7 @@ module Yahns::Acceptor # :nodoc: sleep 1 # let other threads do some work rescue => e Yahns::Log.exception(logger, "accept loop", e) - end until t[:yahns_quit] + end until @quit end end end diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb index 5411c48..43caae6 100644 --- a/lib/yahns/server.rb +++ b/lib/yahns/server.rb @@ -450,7 +450,7 @@ class Yahns::Server # :nodoc: @queues.each(&:close).clear # we must not let quitter get GC-ed if we have any worker threads leftover - @wthr.each { |t| t[:yahns_quitter] = quitter } + @quitter = quitter quitter.close rescue => e -- cgit v1.2.3-24-ge0c7