summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/WaitQueue.lua
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-03-22 21:04:48 +0900
committerNat Goodspeed <nat@lindenlab.com>2024-03-22 21:04:48 +0900
commitbb39a8b223f78205a10ffcb61e3b3bfe05b3fd1a (patch)
tree77beefb75440e9016a44adfa872227f3790ce3b2 /indra/newview/scripts/lua/WaitQueue.lua
parent0566af988790e95414ed18cd82206710094d8fae (diff)
Fix a couple bugs in fiber.lua machinery.
This fixes a hang if the Lua script explicitly calls fiber.run() before LuaState::expr()'s implicit fiber.run() call. Make fiber.run() remove the calling fiber from the ready list to avoid an infinite loop when all other fibers have terminated: "You're ready!" "Okay, yield()." "You're ready again!" ... But don't claim it's waiting, either, because then when all other fibers have terminated, we'd call idle() in the vain hope that something would make that one last fiber ready. WaitQueue:_wake_waiters() needs to wake waiting fibers if the queue's not empty OR it's been closed. Introduce leap.WaitFor:close() to close the queue gracefully so that a looping waiter can terminate, instead of using WaitFor:exception(), which stops the whole script once it propagates. Make leap's cleanup() function call close(). Streamline fiber.get_name() by using 'or' instead of if ... then. Streamline fiber.status() and fiber.set_waiting() by using table.find() instead of a loop.
Diffstat (limited to 'indra/newview/scripts/lua/WaitQueue.lua')
-rw-r--r--indra/newview/scripts/lua/WaitQueue.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/indra/newview/scripts/lua/WaitQueue.lua b/indra/newview/scripts/lua/WaitQueue.lua
index b15e9c443b..f69baff09b 100644
--- a/indra/newview/scripts/lua/WaitQueue.lua
+++ b/indra/newview/scripts/lua/WaitQueue.lua
@@ -38,7 +38,7 @@ function WaitQueue:_wake_waiters()
-- Unlike OS threads, with cooperative concurrency it doesn't make sense
-- to "notify all": we need wake only one of the waiting Dequeue()
-- callers.
- if not self:IsEmpty() and next(self._waiters) then
+ if ((not self:IsEmpty()) or self._closed) and next(self._waiters) then
-- Pop the oldest waiting coroutine instead of the most recent, for
-- more-or-less round robin fairness. But skip any coroutines that
-- have gone dead in the meantime.