From ccd923c44f2a50d5cc761f6f16787b8d0a6cf6a0 Mon Sep 17 00:00:00 2001 From: mippo520 <2570916196@qq.com> Date: Mon, 27 May 2024 18:31:51 +0800 Subject: [PATCH] =?UTF-8?q?skynet.wait=E4=B8=AD=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?session=E5=A2=9E=E5=8A=A0=E5=9B=9E=E7=BB=95=E5=88=A4=E6=96=AD?= =?UTF-8?q?=20(#1931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * skynet.wait中使用的session增加回绕判断 * 去除session判空 --------- Co-authored-by: mippo --- lualib/skynet.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lualib/skynet.lua b/lualib/skynet.lua index e1322965..5b5762c3 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -70,7 +70,7 @@ local watching_session = {} local error_queue = {} local fork_queue = { h = 1, t = 0 } -local auxsend, auxtimeout +local auxsend, auxtimeout, auxwait do ---- avoid session rewind conflict local csend = c.send local cintcommand = c.intcommand @@ -140,6 +140,12 @@ do ---- avoid session rewind conflict return session end + local function auxwait_checkconflict() + local session = c.genid() + checkconflict(session) + return session + end + local function auxsend_checkrewind(addr, proto, msg, sz) local session = csend(addr, proto, nil, msg, sz) if session and session > dangerzone_low and session <= dangerzone_up then @@ -158,15 +164,26 @@ do ---- avoid session rewind conflict return session end + local function auxwait_checkrewind() + local session = c.genid() + if session > dangerzone_low and session <= dangerzone_up then + -- enter dangerzone + set_checkconflict(session) + end + return session + end + set_checkrewind = function() auxsend = auxsend_checkrewind auxtimeout = auxtimeout_checkrewind + auxwait = auxwait_checkrewind end set_checkconflict = function(session) reset_dangerzone(session) auxsend = auxsend_checkconflict auxtimeout = auxtimeout_checkconflict + auxwait = auxwait_checkconflict end -- in safezone at the beginning @@ -516,7 +533,7 @@ function skynet.yield() end function skynet.wait(token) - local session = c.genid() + local session = auxwait() token = token or coroutine.running() suspend_sleep(session, token) sleep_session[token] = nil