From 98e6356aed0c757f16267cc2ae921f9c90a249fe Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 25 Mar 2024 16:57:28 -0400 Subject: Add LL.check_stop() entry point and call it in fiber scheduler(). fiber.lua's scheduler() is greedy, in the sense that it wants to run every ready Lua fiber before retrieving the next incoming event from the viewer (and possibly blocking for some real time before it becomes available). But check for viewer shutdown before resuming any suspended-but-ready Lua fiber. --- indra/llcommon/lua_function.cpp | 9 +++++++++ indra/newview/scripts/lua/fiber.lua | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index 962e9ee2fa..9f0abd5674 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -681,6 +681,15 @@ std::pair LuaFunction::getState() return { registry, lookup }; } +/***************************************************************************** +* check_stop() +*****************************************************************************/ +lua_function(check_stop, "ensure that a Lua script responds to viewer shutdown") +{ + LLCoros::checkStop(); + return 0; +} + /***************************************************************************** * help() *****************************************************************************/ diff --git a/indra/newview/scripts/lua/fiber.lua b/indra/newview/scripts/lua/fiber.lua index 7dc67f510c..aebf27357f 100644 --- a/indra/newview/scripts/lua/fiber.lua +++ b/indra/newview/scripts/lua/fiber.lua @@ -222,8 +222,6 @@ local function scheduler() -- processing to the main thread. If called from a coroutine, pass control -- back to the main thread. if coroutine.running() then - -- seize the opportunity to make sure the viewer isn't shutting down --- check_stop() -- this is a real coroutine, yield normally to main thread coroutine.yield() -- main certainly still exists @@ -240,7 +238,7 @@ local function scheduler() repeat for co in live_ready_iter do -- seize the opportunity to make sure the viewer isn't shutting down --- check_stop() + LL.check_stop() -- before we re-append co, is it the only remaining entry? others = next(ready) -- co is live, re-append it to the ready list -- cgit v1.2.3