modlib/threading.lua

19 lines
435 B
Lua
Raw Normal View History

2020-02-09 01:39:54 +01:00
locks={}
function request(resource, func, ...)
if locks[resource] then
table.insert(locks[resource], {func=func, args={...}})
return false
end
locks[resource]={}
return true
end
function free(resource)
if locks[resource] then
local first=locks[resource][1]
if first then
first.func(unpack(first.args), true)
end
end
locks[resource]=nil
return true
end