forked from Hyperion/HyperionOS
restructure for spm
This commit is contained in:
42
Src/Hyperion-kernel/lib/modules/Hyperion/10_io.kmod
Normal file
42
Src/Hyperion-kernel/lib/modules/Hyperion/10_io.kmod
Normal file
@@ -0,0 +1,42 @@
|
||||
--:Minify:--
|
||||
local kernel=...
|
||||
local io = {}
|
||||
kernel.io=io
|
||||
io.eventq={}
|
||||
|
||||
function io.pushEvent(queue, ...)
|
||||
queue=tostring(queue)
|
||||
if not io.eventq[queue] then
|
||||
io.eventq[queue]={}
|
||||
end
|
||||
io.eventq[queue][#io.eventq[queue]+1]={...}
|
||||
end
|
||||
|
||||
function io.bind(queue)
|
||||
queue=tostring(queue)
|
||||
kernel.currentTask.eventq=queue
|
||||
end
|
||||
|
||||
function io.pullEvent()
|
||||
if io.eventq[kernel.currentTask.eventq] then
|
||||
if #io.eventq[kernel.currentTask.eventq]==1 then
|
||||
local event = table.remove(io.eventq[kernel.currentTask.eventq] or {}, 1)
|
||||
io.eventq[kernel.currentTask.eventq]=nil
|
||||
return table.unpack(event)
|
||||
end
|
||||
local event = table.remove(io.eventq[kernel.currentTask.eventq] or {}, 1)
|
||||
if not event then return end
|
||||
return table.unpack(event)
|
||||
end
|
||||
end
|
||||
|
||||
function io.getBoundQueue()
|
||||
return kernel.currentTask.eventq
|
||||
end
|
||||
|
||||
kernel.syscalls["IO_pushEvent"]=io.pushEvent
|
||||
kernel.syscalls["IO_pullEvent"]=io.pullEvent
|
||||
kernel.syscalls["IO_bind"]=io.bind
|
||||
kernel.syscalls["IO_getBoundQueue"]=io.getBoundQueue
|
||||
|
||||
kernel.log("IO pipeline initialized")
|
||||
Reference in New Issue
Block a user