Processors are working nicely, mostly done with the library
This commit is contained in:
parent
593bfd0d8c
commit
03cea2d71a
@ -919,8 +919,7 @@ end
|
|||||||
local sandcount = 1
|
local sandcount = 1
|
||||||
function multi:newProcessor(name,nothread)
|
function multi:newProcessor(name,nothread)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,{__index = self})
|
setmetatable(c,{__index = multi})
|
||||||
local multi,thread = require("multi"):init() -- We need to capture the t in thread
|
|
||||||
local name = name or "Processor_"..sandcount
|
local name = name or "Processor_"..sandcount
|
||||||
sandcount = sandcount + 1
|
sandcount = sandcount + 1
|
||||||
c.Mainloop = {}
|
c.Mainloop = {}
|
||||||
@ -930,18 +929,17 @@ function multi:newProcessor(name,nothread)
|
|||||||
c.process = thread:newThread(function()
|
c.process = thread:newThread(function()
|
||||||
while true do
|
while true do
|
||||||
thread.hold(function() return c.Active end)
|
thread.hold(function() return c.Active end)
|
||||||
__CurrentProcess = c
|
|
||||||
c:uManager()
|
c:uManager()
|
||||||
__CurrentProcess = self
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
c.process.isProcessThread = true
|
c.process.isProcessThread = true
|
||||||
c.process.PID = sandcount
|
c.process.PID = sandcount
|
||||||
c.OnError = c.process.OnError
|
c.OnError = c.process.OnError
|
||||||
function c.run()
|
function c.run()
|
||||||
__CurrentProcess = c
|
|
||||||
c:uManager()
|
c:uManager()
|
||||||
__CurrentProcess = self
|
end
|
||||||
|
function c:AttachThread(t)
|
||||||
|
--
|
||||||
end
|
end
|
||||||
function c.Start()
|
function c.Start()
|
||||||
c.Active = true
|
c.Active = true
|
||||||
|
|||||||
@ -11,13 +11,16 @@ local function bench(_,steps)
|
|||||||
print("Steps/1s: "..steps)
|
print("Steps/1s: "..steps)
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
|
proc = multi:newProcessor("Test")
|
||||||
for i = 1,400 do
|
for i = 1,400 do
|
||||||
thread:newThread(function()
|
thread:newThread("Thread: "..i,function()
|
||||||
while true do
|
while true do
|
||||||
thread.sleep(.1)
|
thread.sleep(.1)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
multi:benchMark(sleep_for,multi.Priority_Core,"Core:"):OnBench(bench)
|
proc:benchMark(sleep_for,multi.Priority_Core,"Core:"):OnBench(bench)
|
||||||
|
|
||||||
multi:mainloop()
|
while true do
|
||||||
|
proc.run()
|
||||||
|
end
|
||||||
@ -22,36 +22,38 @@ end
|
|||||||
]]
|
]]
|
||||||
local multi, thread = require("multi"):init{priority=true}
|
local multi, thread = require("multi"):init{priority=true}
|
||||||
local good = false
|
local good = false
|
||||||
multi:newAlarm(3):OnRing(function()
|
local proc = multi:newProcessor("Test")
|
||||||
|
proc:newAlarm(3):OnRing(function()
|
||||||
good = true
|
good = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
runTest = thread:newFunction(function()
|
runTest = thread:newFunction(function()
|
||||||
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
|
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
|
||||||
print("Testing Basic Features. If this fails most other features will probably not work!")
|
print("Testing Basic Features. If this fails most other features will probably not work!")
|
||||||
multi:newAlarm(2):OnRing(function(a)
|
proc:newAlarm(2):OnRing(function(a)
|
||||||
alarms = true
|
alarms = true
|
||||||
a:Destroy()
|
a:Destroy()
|
||||||
end)
|
end)
|
||||||
multi:newTStep(1,10,1,.1):OnStep(function(t)
|
proc:newTStep(1,10,1,.1):OnStep(function(t)
|
||||||
tsteps = tsteps + 1
|
tsteps = tsteps + 1
|
||||||
end).OnEnd(function(step)
|
end).OnEnd(function(step)
|
||||||
step:Destroy()
|
step:Destroy()
|
||||||
end)
|
end)
|
||||||
multi:newStep(1,10):OnStep(function(s)
|
proc:newStep(1,10):OnStep(function(s)
|
||||||
steps = steps + 1
|
steps = steps + 1
|
||||||
end).OnEnd(function(step)
|
end).OnEnd(function(step)
|
||||||
step:Destroy()
|
step:Destroy()
|
||||||
end)
|
end)
|
||||||
local loop = multi:newLoop(function(l)
|
local loop = proc:newLoop(function(l)
|
||||||
loops = loops + 1
|
loops = loops + 1
|
||||||
end)
|
end)
|
||||||
multi:newTLoop(function(t)
|
proc:newTLoop(function(t)
|
||||||
tloops = tloops + 1
|
tloops = tloops + 1
|
||||||
end,.1)
|
end,.1)
|
||||||
local updater = multi:newUpdater(1):OnUpdate(function()
|
local updater = proc:newUpdater(1):OnUpdate(function()
|
||||||
updaters = updaters + 1
|
updaters = updaters + 1
|
||||||
end)
|
end)
|
||||||
local event = multi:newEvent(function()
|
local event = proc:newEvent(function()
|
||||||
return alarms
|
return alarms
|
||||||
end)
|
end)
|
||||||
event.OnEvent(function(evnt)
|
event.OnEvent(function(evnt)
|
||||||
@ -108,9 +110,9 @@ runTest = thread:newFunction(function()
|
|||||||
else
|
else
|
||||||
print("Connection Test 1: Ok")
|
print("Connection Test 1: Ok")
|
||||||
end
|
end
|
||||||
conn1 = multi:newConnection()
|
conn1 = proc:newConnection()
|
||||||
conn2 = multi:newConnection()
|
conn2 = proc:newConnection()
|
||||||
conn3 = multi:newConnection()
|
conn3 = proc:newConnection()
|
||||||
local c1,c2,c3,c4 = false,false,false,false
|
local c1,c2,c3,c4 = false,false,false,false
|
||||||
local a = conn1(function()
|
local a = conn1(function()
|
||||||
c1 = true
|
c1 = true
|
||||||
@ -146,4 +148,6 @@ end)
|
|||||||
runTest().OnError(function(...)
|
runTest().OnError(function(...)
|
||||||
print("Error:",...)
|
print("Error:",...)
|
||||||
end)
|
end)
|
||||||
multi:mainloop()
|
while true do
|
||||||
|
proc.run()
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user