summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-16 05:53:14 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-16 05:53:14 +0000
commit0d09e1af49b8523a13bc6e5e054000195114b4f0 (patch)
tree4698eca08dc158e23f1ee0247a24e697997fea25 /lib
parent643ef23752d13e9d4976f3c7fc64f36a15a459c2 (diff)
merge revision(s) 55008: [Backport #12342]
* lib/drb/timeridconv.rb: don't use keeper thread. [Bug #12342] * test/drb/ut_timerholder.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/drb/timeridconv.rb40
1 files changed, 17 insertions, 23 deletions
diff --git a/lib/drb/timeridconv.rb b/lib/drb/timeridconv.rb
index 4ea3035f39..423b4563fa 100644
--- a/lib/drb/timeridconv.rb
+++ b/lib/drb/timeridconv.rb
@@ -17,26 +17,27 @@ module DRb
class InvalidIndexError < RuntimeError; end
- def initialize(timeout=600)
+ def initialize(keeping=600)
super()
@sentinel = Object.new
@gc = {}
- @curr = {}
@renew = {}
- @timeout = timeout
- @keeper = keeper
+ @keeping = keeping
+ @expires = Time.now + @keeping
end
def add(obj)
synchronize do
+ rotate
key = obj.__id__
- @curr[key] = obj
+ @renew[key] = obj
return key
end
end
def fetch(key, dv=@sentinel)
synchronize do
+ rotate
obj = peek(key)
if obj == @sentinel
return dv unless dv == @sentinel
@@ -47,42 +48,35 @@ module DRb
end
end
- def include?(key)
- synchronize do
- obj = peek(key)
- return false if obj == @sentinel
- true
- end
- end
-
+ private
def peek(key)
synchronize do
- return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
+ return @renew.fetch(key) { @gc.fetch(key, @sentinel) }
end
end
- private
- def alternate
+ def rotate
synchronize do
- @gc = @curr # GCed
- @curr = @renew
+ return if @expires > Time.now
+ @gc = @renew # GCed
@renew = {}
+ @expires = Time.now + @keeping
end
end
def keeper
Thread.new do
loop do
- alternate
- sleep(@timeout)
+ rotate
+ sleep(@keeping)
end
end
end
end
- # Creates a new TimerIdConv which will hold objects for +timeout+ seconds.
- def initialize(timeout=600)
- @holder = TimerHolder2.new(timeout)
+ # Creates a new TimerIdConv which will hold objects for +keeping+ seconds.
+ def initialize(keeping=600)
+ @holder = TimerHolder2.new(keeping)
end
def to_obj(ref) # :nodoc: