improved keeper thread
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8687b8ffe8
commit
6fca4ecdd1
@ -1,3 +1,10 @@
|
|||||||
|
Tue Mar 1 00:40:35 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
|
* lib/rinda/tuplespace.rb (Rinda::TupleSpace): improved keeper thread.
|
||||||
|
|
||||||
|
* test/rinda/test_rinda.rb: ditto.
|
||||||
|
|
||||||
|
|
||||||
Mon Feb 28 23:10:13 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Mon Feb 28 23:10:13 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* ext/socket/socket.c (Init_socket): IPv6 is not supported although
|
* ext/socket/socket.c (Init_socket): IPv6 is not supported although
|
||||||
|
@ -220,6 +220,15 @@ module Rinda
|
|||||||
@hash = {}
|
@hash = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_expires?
|
||||||
|
@hash.each do |k, v|
|
||||||
|
v.each do |tuple|
|
||||||
|
return true if tuple.expires
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# Add the object to the TupleBag.
|
# Add the object to the TupleBag.
|
||||||
def push(ary)
|
def push(ary)
|
||||||
size = ary.size
|
size = ary.size
|
||||||
@ -288,12 +297,13 @@ module Rinda
|
|||||||
@take_waiter = TupleBag.new
|
@take_waiter = TupleBag.new
|
||||||
@notify_waiter = TupleBag.new
|
@notify_waiter = TupleBag.new
|
||||||
@period = period
|
@period = period
|
||||||
@keeper = keeper
|
@keeper = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Put a tuple into the tuplespace.
|
# Put a tuple into the tuplespace.
|
||||||
def write(tuple, sec=nil)
|
def write(tuple, sec=nil)
|
||||||
entry = TupleEntry.new(tuple, sec)
|
entry = TupleEntry.new(tuple, sec)
|
||||||
|
start_keeper
|
||||||
synchronize do
|
synchronize do
|
||||||
if entry.expired?
|
if entry.expired?
|
||||||
@read_waiter.find_all_template(entry).each do |template|
|
@read_waiter.find_all_template(entry).each do |template|
|
||||||
@ -323,6 +333,7 @@ module Rinda
|
|||||||
def move(port, tuple, sec=nil)
|
def move(port, tuple, sec=nil)
|
||||||
template = WaitTemplateEntry.new(self, tuple, sec)
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
||||||
yield(template) if block_given?
|
yield(template) if block_given?
|
||||||
|
start_keeper
|
||||||
synchronize do
|
synchronize do
|
||||||
entry = @bag.find(template)
|
entry = @bag.find(template)
|
||||||
if entry
|
if entry
|
||||||
@ -356,6 +367,7 @@ module Rinda
|
|||||||
def read(tuple, sec=nil)
|
def read(tuple, sec=nil)
|
||||||
template = WaitTemplateEntry.new(self, tuple, sec)
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
||||||
yield(template) if block_given?
|
yield(template) if block_given?
|
||||||
|
start_keeper
|
||||||
synchronize do
|
synchronize do
|
||||||
entry = @bag.find(template)
|
entry = @bag.find(template)
|
||||||
return entry.value if entry
|
return entry.value if entry
|
||||||
@ -416,13 +428,21 @@ module Rinda
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def keeper
|
def start_keeper
|
||||||
Thread.new do
|
return if @keeper && @keeper.alive?
|
||||||
loop do
|
@keeper = Thread.new do
|
||||||
sleep(@period)
|
while need_keeper?
|
||||||
keep_clean
|
keep_clean
|
||||||
|
sleep(@period)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def need_keeper?
|
||||||
|
return true if @bag.has_expires?
|
||||||
|
return true if @read_waiter.has_expires?
|
||||||
|
return true if @take_waiter.has_expires?
|
||||||
|
return true if @notify_waiter.has_expires?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,8 @@ require 'rinda/tuplespace'
|
|||||||
|
|
||||||
require 'singleton'
|
require 'singleton'
|
||||||
|
|
||||||
|
require 'weakref'
|
||||||
|
|
||||||
module Rinda
|
module Rinda
|
||||||
|
|
||||||
class MockClock
|
class MockClock
|
||||||
@ -499,6 +501,14 @@ class TupleSpaceTest < Test::Unit::TestCase
|
|||||||
ThreadGroup.new.add(Thread.current)
|
ThreadGroup.new.add(Thread.current)
|
||||||
@ts = Rinda::TupleSpace.new(1)
|
@ts = Rinda::TupleSpace.new(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_gc
|
||||||
|
w = WeakRef.new(Rinda::TupleSpace.new)
|
||||||
|
GC.start
|
||||||
|
assert_raises(WeakRef::RefError) do
|
||||||
|
w.__getobj__
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TupleSpaceProxyTest < Test::Unit::TestCase
|
class TupleSpaceProxyTest < Test::Unit::TestCase
|
||||||
|
Loading…
x
Reference in New Issue
Block a user