From 693176efc8ac28a40da7793805fd91f5e593a9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E7=86=8F?= Date: Wed, 24 Jun 2020 16:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sharetable=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20(#1208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zixun --- lualib/skynet/sharetable.lua | 43 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/lualib/skynet/sharetable.lua b/lualib/skynet/sharetable.lua index eb2449a0d..6bec2d268 100644 --- a/lualib/skynet/sharetable.lua +++ b/lualib/skynet/sharetable.lua @@ -258,16 +258,12 @@ local function resolve_replace(replace_map) local function match_value(v) assert(v ~= nil) - if v == RECORD then + if record_map[v] or is_sharedtable(v) then return end local tv = type(v) local f = match[tv] - if record_map[v] or is_sharedtable(v) then - return - end - if f then record_map[v] = true f(v) @@ -364,7 +360,7 @@ local function resolve_replace(replace_map) end local level = info.level - local curco = info.curco or coroutine.running() + local curco = info.curco if not level then return end @@ -390,7 +386,7 @@ local function resolve_replace(replace_map) end local stack_values_tmp = {} - local function match_thread(co) + local function match_thread(co, level) -- match stackvalues local n = stackvalues(co, stack_values_tmp) for i=1,n do @@ -399,40 +395,37 @@ local function resolve_replace(replace_map) match_value(v) end - -- match callinfo - local level = 1 - -- jump the fucntion from sharetable.update to top - local is_self = coroutine.running() == co - if is_self then - while true do - local info = getinfo(co, level, "uf") - level = level + 1 - if not info then - level = 1 - break - elseif info.func == sharetable.update then - break - end - end - end - + level = level or 1 while true do local info = getinfo(co, level, "uf") if not info then break end - info.level = is_self and level + 1 or level + info.level = level info.curco = co match_funcinfo(info) level = level + 1 end end + local function prepare_match() + local co = coroutine.running() + record_map[co] = true + record_map[match] = true + record_map[RECORD] = true + record_map[record_map] = true + record_map[insert_replace] = true + record_map[resolve_replace] = true + assert(getinfo(co, 3, "f").func == sharetable.update) + match_thread(co, 5) -- ignore match_thread and match_funcinfo frame + end + match["table"] = match_table match["function"] = match_function match["userdata"] = match_userdata match["thread"] = match_thread + prepare_match() match_internmt() local root = debug.getregistry()