Fix race condition in task state table unref

This commit is contained in:
2025-06-28 19:52:28 +10:00
parent cea9bc0813
commit d5e85f2c30
3 changed files with 61 additions and 35 deletions

View File

@@ -8,16 +8,15 @@ local function __ref(value)
if ref ~= nil and ref ~= 0 then
__registry[FREELIST_REF] = __registry[ref]
else
ref = #__registry + 1
ref = rawlen(__registry) + 1
end
__registry[ref] = value
return ref
end
local function __unref(ref)
if ref < 0 then return nil end
local value = __registry[ref]
__registry[ref] = __registry[FREELIST_REF]
__registry[FREELIST_REF] = ref
return value
if ref > 0 then
__registry[ref] = __registry[FREELIST_REF]
__registry[FREELIST_REF] = ref
end
end