Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
scripting/lua: scheduler fixes for undefined behavior
  • Loading branch information
blattersturm committed Jul 4, 2019
1 parent ade4b2b commit 39c75bb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion data/shared/citizen/scripting/lua/scheduler.lua
@@ -1,4 +1,10 @@
local threads = {}
local newThreads = {}
local threads = setmetatable({}, {
-- This circumvents undefined behaviour in "next" (and therefore "pairs")
__newindex = newThreads,
-- This is needed for CreateThreadNow to work correctly
__index = newThreads
})

--[[
Expand Down Expand Up @@ -97,6 +103,11 @@ SetTimeout = Citizen.SetTimeout
Citizen.SetTickRoutine(function()
local curTime = GetGameTimer()

for coro, thread in pairs(newThreads) do
rawset(threads, coro, thread)
newThreads[coro] = nil
end

for coro, thread in pairs(threads) do
if curTime >= thread.wakeTime then
resumeThread(coro)
Expand Down

0 comments on commit 39c75bb

Please sign in to comment.