clear dead response in sharedatad

This commit is contained in:
Cloud Wu
2014-09-27 14:55:14 +08:00
parent 016b4dc58f
commit c8775ee6f5
2 changed files with 25 additions and 2 deletions

View File

@@ -331,6 +331,7 @@ function skynet.time()
end end
function skynet.exit() function skynet.exit()
fork_queue = {} -- no fork coroutine can be execute after skynet.exit
skynet.send(".launcher","lua","REMOVE",skynet.self()) skynet.send(".launcher","lua","REMOVE",skynet.self())
-- report the sources that call me -- report the sources that call me
for co, session in pairs(session_coroutine_id) do for co, session in pairs(session_coroutine_id) do

View File

@@ -4,6 +4,7 @@ local table = table
local NORET = {} local NORET = {}
local pool = {} local pool = {}
local pool_count = {}
local objmap = {} local objmap = {}
local function newobj(name, tbl) local function newobj(name, tbl)
@@ -13,6 +14,7 @@ local function newobj(name, tbl)
local v = { value = tbl , obj = cobj, watch = {} } local v = { value = tbl , obj = cobj, watch = {} }
objmap[cobj] = v objmap[cobj] = v
pool[name] = v pool[name] = v
pool_count[name] = { n = 0, threshold = 16 }
end end
local function collectobj() local function collectobj()
@@ -55,10 +57,11 @@ end
function CMD.delete(name) function CMD.delete(name)
local v = assert(pool[name]) local v = assert(pool[name])
pool[name] = nil pool[name] = nil
pool_count[name] = nil
assert(objmap[v.obj]) assert(objmap[v.obj])
objmap[v.obj] = true objmap[v.obj] = true
sharedata.host.decref(v.obj) sharedata.host.decref(v.obj)
for _,response in ipairs(v.watch) do for _,response in pairs(v.watch) do
response(true) response(true)
end end
end end
@@ -86,23 +89,42 @@ function CMD.update(name, t)
objmap[oldcobj] = true objmap[oldcobj] = true
sharedata.host.decref(oldcobj) sharedata.host.decref(oldcobj)
pool[name] = nil pool[name] = nil
pool_count[name] = nil
end end
CMD.new(name, t) CMD.new(name, t)
local newobj = pool[name].obj local newobj = pool[name].obj
if watch then if watch then
sharedata.host.markdirty(oldcobj) sharedata.host.markdirty(oldcobj)
for _,response in ipairs(watch) do for _,response in pairs(watch) do
response(true, newobj) response(true, newobj)
end end
end end
end end
local function check_watch(queue)
local n = 0
for k,response in pairs(queue) do
if not response "TEST" then
queue[k] = nil
n = n + 1
end
end
return n
end
function CMD.monitor(name, obj) function CMD.monitor(name, obj)
local v = assert(pool[name]) local v = assert(pool[name])
if obj ~= v.obj then if obj ~= v.obj then
return v.obj return v.obj
end end
local n = pool_count[name].n
pool_count[name].n = n + 1
if n > pool_count[name].threshold then
n = n - check_watch(v.watch)
pool_count[name].threshold = n * 2
end
table.insert(v.watch, skynet.response()) table.insert(v.watch, skynet.response())
return NORET return NORET