1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-13 00:27:00 -05:00
OC-PsychOS2/module/sched.lua
2018-11-03 03:05:41 +11:00

23 lines
513 B
Lua

tTasks,nPid,nTimeout,cPid = {},1,1,0
function os.spawn(f,n)
tTasks[nPid] = {["c"]=coroutine.create(f),["n"]=n,["p"]=nPid}
for k,v in pairs(tTasks[cPid] or {}) do
tTasks[nPid][k] = tTasks[nPid][k] or v
end
nPid = nPid + 1
return nPid - 1
end
function sched()
while #tTasks > 0 do
local tEv = {computer.pullSignal(nTimeout)}
for k,v in pairs(tTasks) do
if coroutine.status(v.c) ~= "dead" then
cPid = k
coroutine.resume(v.c,table.unpack(tEv))
else
tTasks[k] = nil
end
end
end
end