1
1
의 미러 https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-09-28 15:12:45 -04:00

added a proper environment variable system rather than just sticking stuff in the process' table

This commit is contained in:
XeonSquared 2019-01-02 16:41:39 +11:00
부모 7615cf67dc
커밋 d71dec7b8d

파일 보기

@ -1,13 +1,19 @@
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
do
tTasks,nPid,nTimeout,cPid = {},1,1,0 -- table of tasks, next process ID, event timeout, current PID
function os.spawn(f,n) -- creates a process from function *f* with name *n*
tTasks[nPid] = {["c"]=coroutine.create(f),["n"]=n,["p"]=nPid,e={}}
if tTasks[cPid] then
for k,v in pairs(tTasks[cPid].e) do
tTasks[nPid].e[k] = tTasks[nPid].e[k] or v
end
end
nPid = nPid + 1
return nPid - 1
end
function sched()
function os.kill(pid) -- removes process *pid* from the task list
tTasks[pid] = nil
end
function sched() -- the actual scheduler function
while #tTasks > 0 do
local tEv = {computer.pullSignal(nTimeout)}
for k,v in pairs(tTasks) do
@ -20,3 +26,14 @@ function sched()
end
end
end
function os.setenv(k,v) -- set's the current process' environment variable *k* to *v*, which is passed to children
if tTasks[cPid] then
tTasks[cPid].e[k] = v
end
end
function os.getenv(k) -- gets a process' *k* environment variable
if tTasks[cPid] then
return tTasks[cPid].e[k]
end
end
end