2019-11-08 22:23:47 -05:00
|
|
|
local gpus,screens,ttyn,pids = {}, {}, 0, {}
|
2019-11-03 16:55:04 -05:00
|
|
|
local function scan()
|
|
|
|
local w,di = pcall(computer.getDeviceInfo)
|
|
|
|
if w then
|
|
|
|
for a,t in pairs(component.list()) do
|
|
|
|
if t == "gpu" then
|
|
|
|
gpus[a] = gpus[a] or {false, tonumber(di[a].capacity)}
|
|
|
|
elseif t == "screen" then
|
|
|
|
screens[a] = screens[a] or {false, tonumber(di[a].capacity)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
dprint("no getDevInfo")
|
|
|
|
for a,t in pairs(component.list()) do
|
|
|
|
if t == "gpu" then
|
|
|
|
gpus[a] = gpus[a] or {false, 8000}
|
|
|
|
elseif t == "screen" then
|
|
|
|
screens[a] = screens[a] or {false, 8000}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function nextScreen(n)
|
|
|
|
local rt = {}
|
|
|
|
for k,v in pairs(screens) do
|
|
|
|
if not v[1] then
|
|
|
|
rt[v[2]] = rt[v[2]] or k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return rt[n] or rt[8000] or rt[2000] or rt[600]
|
|
|
|
end
|
2019-11-08 22:23:47 -05:00
|
|
|
|
|
|
|
local function spawnShell(fin,fout)
|
|
|
|
io.input(fin)
|
2020-03-16 02:30:22 -04:00
|
|
|
io.output(fout):setvbuf("no")
|
2019-11-08 22:23:47 -05:00
|
|
|
print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
|
|
|
|
return os.spawnfile("/boot/exec/shell.lua")
|
|
|
|
end
|
|
|
|
|
2019-11-03 16:55:04 -05:00
|
|
|
local function allocate()
|
|
|
|
for k,v in pairs(gpus) do
|
|
|
|
dprint(k)
|
|
|
|
local sA = nextScreen(v[2])
|
|
|
|
if v[1] == false and sA then
|
|
|
|
local r,w = vtemu(k,sA)
|
|
|
|
devfs.register("tty"..tostring(ttyn), function() return r,w,function() end end)
|
|
|
|
gpus[k][1] = true
|
|
|
|
screens[sA][1] = true
|
2019-11-08 22:23:47 -05:00
|
|
|
pids["tty"..tostring(ttyn)] = {-1}
|
2019-11-03 16:55:04 -05:00
|
|
|
ttyn = ttyn + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-08 22:23:47 -05:00
|
|
|
|
2019-11-03 16:55:04 -05:00
|
|
|
scan()
|
|
|
|
allocate()
|
|
|
|
dprint("screens ready")
|
|
|
|
while true do
|
|
|
|
coroutine.yield()
|
2019-11-08 22:23:47 -05:00
|
|
|
for k,v in pairs(pids) do
|
|
|
|
if not os.taskInfo(v[1]) then
|
|
|
|
dprint("Spawning new shell for "..k)
|
|
|
|
pids[k][1] = spawnShell(v[2] or "/dev/"..k, v[3] or "/dev/"..k)
|
|
|
|
pids[k][2], pids[k][3] = pids[k][2] or io.input(), pids[k][3] or io.output()
|
|
|
|
end
|
|
|
|
end
|
2019-11-03 16:55:04 -05:00
|
|
|
end
|