From d98f3539360fa7f2e1849e9dd3b65115365e248c Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Mon, 17 Jan 2022 23:23:56 -0500 Subject: [PATCH] Tweaked processor object, added lightloop and lmanager --- changes.md | 7 ++++++ multi/init.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++++---- test3.lua | 23 ++++++++++++++++--- 3 files changed, 84 insertions(+), 7 deletions(-) diff --git a/changes.md b/changes.md index c8d9d83..e0a8128 100644 --- a/changes.md +++ b/changes.md @@ -13,6 +13,11 @@ Full Update Showcase Added: --- +- multi:lManager() the uManager() to mainloop() equivalent to lightloop() + - A lightweight version of uManager() Priorities are not supported! + +- multi:newProcessor(name,nothread).run() + - new function run to the processor object to - multi:newTLoop() member functions - `TLoop:Set(set)` - Sets the time to wait for the TLoop @@ -26,6 +31,8 @@ Added: Changed: --- +- `multi:newProcessor(name,nothread)` The new argument allows you to tell the system you won't be using the Start() and Stop() functions, rather you will handle the process yourself. Using the proc.run() function. This function needs to be called to pump the events. + - Processors now also use lManager instead of uManager. - `multi.hold(n,opt)` now supports an option table like thread.hold does. - Connection Objects now pass on the parent object if created on a multiobj. This was to allow chaining to work properly with the new update diff --git a/multi/init.lua b/multi/init.lua index 0348e22..02f98d6 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -912,7 +912,7 @@ function multi.getCurrentTask() end local sandcount = 1 -function multi:newProcessor(name) +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 @@ -920,12 +920,12 @@ function multi:newProcessor(name) sandcount = sandcount + 1 c.Mainloop = {} c.Type = "process" - c.Active = false + c.Active = false or nothread c.Name = name or "" c.process = self:newThread(c.Name,function() while true do thread.hold(function() - return c.Active + return c.Active and not(nothread) end) __CurrentProcess = c c:uManager() @@ -935,6 +935,11 @@ function multi:newProcessor(name) 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.Start() c.Active = true return self @@ -1632,6 +1637,7 @@ function multi:lightloop(settings) local Loop=self.Mainloop local ctask while true do + __CurrentProcess = self for _D=#Loop,1,-1 do __CurrentTask = Loop[_D] ctask = __CurrentTask @@ -1899,8 +1905,55 @@ function multi:uManager(settings) end multi.OnLoad:Fire() self.uManager=self.uManagerRef + self.lManager=self.lManagerRef end -function multi:uManagerRef(settings) +function multi:lManager(settings) + __CurrentProcess = self + multi.OnPreLoad:Fire() + multi.defaultSettings = settings or multi.defaultSettings + self.t,self.tt = clock(),0 + if settings then + priority = settings.priority + if settings.auto_priority then + priority = -1 + end + if settings.preLoop then + settings.preLoop(self) + end + if settings.stopOnError then + stopOnError = settings.stopOnError + end + multi.defaultSettings.p_i = self.Priority_Idle + if settings.auto_stretch then + multi.defaultSettings.p_i = settings.auto_stretch*self.Priority_Idle + end + multi.defaultSettings.delay = settings.auto_delay or 3 + multi.defaultSettings.auto_lowerbound = settings.auto_lowerbound or self.Priority_Idle + protect = settings.protect + end + multi.OnLoad:Fire() + self.uManager=self.uManagerRef + self.lManager=self.lManagerRef +end +function multi:lManagerRef() + if self.Active then + local Loop=self.Mainloop + local ctask + while true do + __CurrentProcess = self + for _D=#Loop,1,-1 do + __CurrentTask = Loop[_D] + ctask = __CurrentTask + if ctask.Active then + if not protect then + ctask:Act() + end + end + end + end + end +end +function multi:uManagerRef() if self.Active then local Loop=self.Mainloop local PS=self diff --git a/test3.lua b/test3.lua index ed8d0d6..94458d5 100644 --- a/test3.lua +++ b/test3.lua @@ -22,8 +22,25 @@ local multi,thread = require("multi"):init() -- print("Function Done",handler.getReturns()) -- print("Function Done",handler2.getReturns()) -- end) -multi:benchMark(1):OnBench(function(sec,steps) + + +-- multi:benchMark(1):OnBench(function(sec,steps) +-- print("Steps:",steps) +-- os.exit() +-- end) + + +local test = multi:newProcessor("test",true) +test:benchMark(1):OnBench(function(sec,steps) print("Steps:",steps) - os.exit() + --os.exit() end) -multi:mainloop() \ No newline at end of file +test:newThread(function() + while true do + thread.sleep(1) + print("hi") + end +end) +test:lightloop() + +-- multi:lightloop() \ No newline at end of file