From 03cea2d71a9a4cf3c935481ba497feea5da36d98 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Sat, 5 Feb 2022 10:56:03 -0500 Subject: [PATCH] Processors are working nicely, mostly done with the library --- multi/init.lua | 10 ++++------ test4.lua | 9 ++++++--- tests/runtests.lua | 28 ++++++++++++++++------------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/multi/init.lua b/multi/init.lua index b3c7b30..6b9d36f 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -919,8 +919,7 @@ end local sandcount = 1 function multi:newProcessor(name,nothread) local c = {} - setmetatable(c,{__index = self}) - local multi,thread = require("multi"):init() -- We need to capture the t in thread + setmetatable(c,{__index = multi}) local name = name or "Processor_"..sandcount sandcount = sandcount + 1 c.Mainloop = {} @@ -930,18 +929,17 @@ function multi:newProcessor(name,nothread) c.process = thread:newThread(function() while true do thread.hold(function() return c.Active end) - __CurrentProcess = c c:uManager() - __CurrentProcess = self end end) c.process.isProcessThread = true c.process.PID = sandcount c.OnError = c.process.OnError function c.run() - __CurrentProcess = c c:uManager() - __CurrentProcess = self + end + function c:AttachThread(t) + -- end function c.Start() c.Active = true diff --git a/test4.lua b/test4.lua index 6c0b527..fbf7b18 100644 --- a/test4.lua +++ b/test4.lua @@ -11,13 +11,16 @@ local function bench(_,steps) print("Steps/1s: "..steps) os.exit() end +proc = multi:newProcessor("Test") for i = 1,400 do - thread:newThread(function() + thread:newThread("Thread: "..i,function() while true do thread.sleep(.1) 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() \ No newline at end of file +while true do + proc.run() +end \ No newline at end of file diff --git a/tests/runtests.lua b/tests/runtests.lua index fdedeb9..2c45222 100644 --- a/tests/runtests.lua +++ b/tests/runtests.lua @@ -22,36 +22,38 @@ end ]] local multi, thread = require("multi"):init{priority=true} local good = false -multi:newAlarm(3):OnRing(function() +local proc = multi:newProcessor("Test") +proc:newAlarm(3):OnRing(function() good = true end) + runTest = thread:newFunction(function() 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!") - multi:newAlarm(2):OnRing(function(a) + proc:newAlarm(2):OnRing(function(a) alarms = true a:Destroy() end) - multi:newTStep(1,10,1,.1):OnStep(function(t) + proc:newTStep(1,10,1,.1):OnStep(function(t) tsteps = tsteps + 1 end).OnEnd(function(step) step:Destroy() end) - multi:newStep(1,10):OnStep(function(s) + proc:newStep(1,10):OnStep(function(s) steps = steps + 1 end).OnEnd(function(step) step:Destroy() end) - local loop = multi:newLoop(function(l) + local loop = proc:newLoop(function(l) loops = loops + 1 end) - multi:newTLoop(function(t) + proc:newTLoop(function(t) tloops = tloops + 1 end,.1) - local updater = multi:newUpdater(1):OnUpdate(function() + local updater = proc:newUpdater(1):OnUpdate(function() updaters = updaters + 1 end) - local event = multi:newEvent(function() + local event = proc:newEvent(function() return alarms end) event.OnEvent(function(evnt) @@ -108,9 +110,9 @@ runTest = thread:newFunction(function() else print("Connection Test 1: Ok") end - conn1 = multi:newConnection() - conn2 = multi:newConnection() - conn3 = multi:newConnection() + conn1 = proc:newConnection() + conn2 = proc:newConnection() + conn3 = proc:newConnection() local c1,c2,c3,c4 = false,false,false,false local a = conn1(function() c1 = true @@ -146,4 +148,6 @@ end) runTest().OnError(function(...) print("Error:",...) end) -multi:mainloop() \ No newline at end of file +while true do + proc.run() +end \ No newline at end of file