* libs/util: Fixed memory leaks in threadlocal implementations
This commit is contained in:
parent
02cce96c83
commit
1e413b9251
1 changed files with 3 additions and 8 deletions
|
@ -281,16 +281,9 @@ function threadlocal()
|
||||||
rawset(self, thread, {})
|
rawset(self, thread, {})
|
||||||
end
|
end
|
||||||
rawget(self, thread)[key] = value
|
rawget(self, thread)[key] = value
|
||||||
|
|
||||||
-- Avoid memory leaks by removing abandoned stores
|
|
||||||
for k, v in pairs(self) do
|
|
||||||
if type(k) == "thread" and coroutine.status(k) == "dead" then
|
|
||||||
rawset(self, k, nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(tbl, {__index = get, __newindex = set})
|
setmetatable(tbl, {__index = get, __newindex = set, __mode = "k"})
|
||||||
|
|
||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
@ -404,6 +397,7 @@ end
|
||||||
local performResume, handleReturnValue
|
local performResume, handleReturnValue
|
||||||
local oldpcall, oldxpcall = pcall, xpcall
|
local oldpcall, oldxpcall = pcall, xpcall
|
||||||
coxpt = {}
|
coxpt = {}
|
||||||
|
setmetatable(coxpt, {__mode = "kv"})
|
||||||
|
|
||||||
function handleReturnValue(err, co, status, ...)
|
function handleReturnValue(err, co, status, ...)
|
||||||
if not status then
|
if not status then
|
||||||
|
@ -429,6 +423,7 @@ function coxpcall(f, err, ...)
|
||||||
end
|
end
|
||||||
local c = coroutine.running()
|
local c = coroutine.running()
|
||||||
coxpt[co] = coxpt[c] or c or 0
|
coxpt[co] = coxpt[c] or c or 0
|
||||||
|
|
||||||
return performResume(err, co, ...)
|
return performResume(err, co, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue